Graphics Reference
In-Depth Information
There is no need to report back to the user past third position in this game, so specific
messages end there. Any position higher than third will display a message simply saying
“Finished” instead:
if ( finalPosition == 1 )
finalPositionText.text = "FINISHED 1st";
if ( finalPosition == 2 )
finalPositionText.text = "FINISHED 2nd";
if ( finalPosition == 3 )
finalPositionText.text = "FINISHED 3rd";
if ( finalPosition >= 4 )
finalPositionText.text = "FINISHED";
Here's the doneFinalMessage Boolean variable again, being set to true now that the
message has been set up:
doneFinalMessage = true;
The finalPositionText object's gameObject was set inactive (hidden) at the start of
this class by the Init() function. Since we need to display it again now, the call goes out to
GameObject.SetActive() again, this time setting it to true so the message is visible:
finalPositionText.gameObject.SetActive(true);
The race is done. We know this, as the RaceComplete() function only gets called once
at the end of the race. After it is called, the code below schedules a call to FinishRace() in
10 s time via Unity's Invoke function:
// drop out of the race scene completely in 10
// seconds...
Invoke( "FinishRace", 10 );
}
}
When it is called, FinishRace() will load the main menu, effectively ending the game
altogether:
void FinishRace ()
{
Application.LoadLevel( mainMenuSceneName );
}
The ShowCount1(), ShowCount2(), and ShowCount3() functions switch the active
states of the user interface objects used to display the numbers during the 3-2-1 countdown
at the start of the race:
void ShowCount1 ()
{
count1.SetActive( true );
count2.SetActive( false );
Search WWH ::




Custom Search