Graphics Reference
In-Depth Information
}
public GameObject GetMainPlayerGO ()
{
return playerGO1;
}
When the main player is destroyed, the PlayerDied() function is called. It tells the
UI controller to display a message (a game-over message) and schedules the exiting of the
game 5 seconds from the time that the call is made.
The ID of the player is passed into this function, though it remains unused in its
current form. This is purely to maintain a standardized system, where under other cir-
cumstances (such as local multiplayer games) the ID might be checked to see which player
died and react accordingly. In this case, as we know that there is only one player (it is a
single-player game example, after all!), it is assumed that the game is over without having
to check IDs:
public void PlayerDied(int whichID)
{
// this is a single player game, so just end the game now
// both players are dead, so end the game
UIControl.ShowGameOver();
Invoke ("Exit",5);
}
When the Exit() function is called (as scheduled by the PlayerDied() function earlier),
Application.LoadLevel will switch scenes away from the game and in to the main menu. The
mainMenuSceneName string should be set by the Inspector window in the Unity editor to
the name of the main menu scene, although its default declaration early in this script will, by
default, be set to the name of the main menu in the example game:
void Exit()
{
Application.LoadLevel( mainMenuSceneName );
}
The UIControl.cs script will be analyzed in full later in this chapter. Game control-
ler needs to tell it about lives and score changes, which it does so through the functions
UpdateScoreP1() and UpdateLivesP1():
// UI update calls
//
public void UpdateScoreP1( int aScore )
{
UIControl.UpdateScoreP1( aScore );
}
public void UpdateLivesP1( int aScore )
{
UIControl.UpdateLivesP1( aScore );
}
}
Search WWH ::




Custom Search