Graphics Reference
In-Depth Information
Although this is not a battle, the game follows a similar format to Metal Vehicle Doom
in terms of its position list: a leaderboard-like scoring system. To keep this up to date, a
repeating Invoke calls UpdatePositions() every half second:
// update positions throughout the battle, but we don't need
// to do this every frame, so just do it every half a second instead
InvokeRepeating( "UpdatePositions", 0f, 0.5f );
// hide our count-in numbers
HideCount();
// schedule count-in messages
Invoke( "ShowCount3", 1 );
Invoke( "ShowCount2", 2 );
Invoke( "ShowCount1", 3 );
In the Metal Vehicle Doom Init() function, the final Invoke call was to HideCount(), but
in this function, there is something else that needs to be done before starting the game that
happens in the FinishedCount() function, so the call is made to FinishedCount() instead
of HideCount():
Invoke( "FinishedCount", 4 );
// hide final position text
finalPositionText.gameObject.SetActive( false );
doneFinalMessage = false;
didInit=true;
}
Further down in the script, UpdateBattlePositionText() updates GUIText components
with the current time left on the timer and a list of players and their positions on the score
board:
void UpdateBattlePositionText ()
{
The TimerClass script has a function called GetFormattedTime(), which returns a
string containing the time formatted as mm:ss:ms. The timer GUIText component's text
is set to the function's return value here:
// get a string back from the timer to display on screen
timerText.text = theTimer.GetFormattedTime();
There is a function in the global battle manager called GetPositionListString() that
will not only return a sorted score list but also return it as a formatted string with line
breaks in it, ready to put right into a GUIText component:
// get the current player position scoreboard from the
// battle manager and show it via posText.text
posText.text = GlobalBattleManager.Instance.
GetPositionListString();
In all honesty, this may not be the best place for this to happen (since it's supposed to
be a UI-specific function), but it does serve to keep all of the timer logic in one function.
Here the timer is checked to see whether it is time to end the game.
Search WWH ::




Custom Search