Graphics Reference
In-Depth Information
public void Start()
{
// we want to keep the game controller alive right through
// the game, so we use DontDestroyOnLoad to keep it alive
DontDestroyOnLoad (this.gameObject);
}
When a new scene is loaded, the LevelLoadingComplete() function gets called by an
instance of the LevelSetup.cs script. The script here can then reinitialize itself and the user
interface so that the game can continue in the new scene:
public void LevelLoadingComplete()
{
Init();
UIControl.Init();
}
The Init() function is composed in such a way as to be reusable and will be called at
the start of each level:
public void Init()
{
The player starts out held in place. An Invoke call to StartPlayer schedules the player
to be released 4 s after this function is called:
// tell the player that it can move, in 4 seconds
Invoke ("StartPlayer",4);
The Time.timeScale value can affect the whole feel of the game. Some shooters demand
more enemies and slower movement, and some have faster movement and fewer enemies;
the movement and update speeds of the game are determined by the type of game you are
building (including artistic style, world type, and any other game elements that may affect
the overall pace). The gameSpeed variable can be set to change time scale, and the code
here changes the physics engine time setting to suit:
// in case we need to change the time scale, it gets set here
Time.timeScale=gameSpeed;
This game allows for one or two players. The main menu scene displays an extra button
for cooperative play. By starting the game through this additional button, a preferences key is
written called totalPlayers. The first main game scene is then loaded in the same way.
At this stage in the Init() function, the PlayerPrefs value is retrieved, stored in the
integer type variable totalPlayers, and used to setup the game differently:
// we store the current game's number of players in a pref so it
// may be set elsewhere (the main menu for example) and
// carried into every level of the game.
if(PlayerPrefs.HasKey( "totalPlayers" )) // does this pref exist?
{
totalPlayers= PlayerPrefs.GetInt( "totalPlayers" );
// then use the value it holds
} else {
totalPlayers= 1; // default to single player
}
Search WWH ::




Custom Search