Graphics Reference
In-Depth Information
public void PlayerDied(int whichID)
{
if(whichID==1)
player1Dead=true;
if(whichID==2)
player2Dead=true;
if(player1Dead && player2Dead && totalPlayers>1)
{
// both players are dead, so end the game
UIControl.ShowGameOver();
Invoke ("Exit",5);
} else if(totalPlayers==1)
{
// 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);
}
}
void Exit()
{
SpawnController.Instance.Restart();
Destroy( this.gameObject );
// make sure we have a scene manager to talk to
GetSceneManager ();
sceneManager.LoadLevel( mainMenuSceneName );
}
}
14.3.2.1 Script Breakdown
The GameController_IP script is based on BaseGameController:
using UnityEngine;
using System.Collections;
public class GameController_IP : BaseGameController
{
When GameController_IP is instantiated, the static variable Instance is populated
with a reference to this script, so that it can be accessed from other scripts in the scene:
public GameController_IP()
{
Instance=this;
}
To keep the game controller alive between scenes, the Start() function makes a call to
DontDestroyOnLoad():
Search WWH ::




Custom Search