Game Development Reference
In-Depth Information
1.
Open the SensorDoors script.
2.
Add the following variable:
LevelManager levelManager; // the script that holds the data between levels
Find it in the Start function, and assign it if found:
3.
if(GameObject.Find("Level Manager")) {
levelManager = GameObject.Find("Level Manager").GetComponent<LevelManager>();
}
Because the Level Manager exists only in the StartMenu scene in edit mode, you can't drag and
drop it in the GardenLevel1 scene. It can be found only after the level has started. And it can be
assigned only if it has been found.
If the SensorDoor script has been started—e.g., you are in a garden level—you will find out what
state the game is currently in and, if it is currently set as state 0, you will update it to state 1.
In the Start function, below the levelManager = line, add the following:
4.
if(levelManager.gameState < 1) levelManager.gameState = 1; // in staging area
If the player has triggered the door and the game is not already in play, the game is now in play,
so you will report the new gameState , 2, to the Level Manager.
In the SetGameOn function, add
5.
// game is running, inform the LevelManager
if(levelManager) levelManager.gameState = 2;
6. Save the script.
The LevelManager script is where the gameState value will be kept.
7.
In the LevelManager script, add the following variable:
public int gameState = 0; // 0, new game, 1, staging area, 2, in garden
8.
Save the script.
9.
Open the StartScene, and select the Level Manager object.
10.
Click Play, and go into the game.
11.
Resize the Inspector panel to force the update so you can see the new game
state, 1.
12.
Drive into the garden, and force another update to see the new state value, 2.
13.
Stop Play mode, and save the scene.
 
Search WWH ::




Custom Search