Graphics Reference
In-Depth Information
public class GameController_LBS : BaseGameController
{
When the game has finished, the string type variable mainMenuSceneName is used
to load the main menu. The main menu scene of this game is named “menu_LBS”:
public string mainMenuSceneName = "menu_LBS";
Skipping past the variable declarations (as their functions should become obvious as
the script is analyzed later in this section), there is a constructor for GameController_LBS.
When this script is attached to a GameObject, the constructor will be called when the
game first starts (as constructors are called when an instance of a script is made).
The constructor sets the static variable named Instance to the instance of the script
that this function is being called on. From here on, when another script needs to talk to
the game controller it can do so through GameController_LBS.Instance():
public GameController_LBS()
{
Instance=this;
}
Time.timeScale need not always be set to 1. gameSpeed is a public variable which may
be used to set the game timing to one that makes for a specific type of game play experi-
ence. When Start() is called by the Unity engine, the time scale is set just after Init() is
called:
public void Start()
{
Init();
Time.timeScale=gameSpeed;
}
The player will not be allowed to move straight away, and the Init() function schedules
a call, with the Invoke method, to start player movement 1 second later.
This Init() function will be called when the game restarts. When the game restarts,
SpawnController may still hold references to the old objects it has spawned. By calling
Restart() on its instance, everything gets cleared out ready for a new round:
public void Init()
{
Invoke ("StartPlayer",1);
SpawnController.Instance.Restart();
Rather than hard-coding a player prefab or specific player objects, to keep things flex-
ible the game controller uses an array named playerPrefabList. Player prefab references
are added via the Inspector window in the Unity editor, and the game controller uses the
array to spawn them when the game starts. numberOfPlayers holds a count of the players
in the playerPrefabList array:
numberOfPlayers= playerPrefabList.Length;
Search WWH ::




Custom Search