Game Development Reference
In-Depth Information
The console is once again clear and happy.
1.
In the GardenLevel1 scene, select the Game Manager.
2.
In its Game Misc component, load the Game Manager into its Score Keeper
parameter and the Battery Life object into its Battery Health parameter
(Figure 10-42 ).
Figure 10-42. The Game Misc component on the Game Manager object
With the data flying back and forth between the scripts, the next task will be to have the Level
Manager process it. The GameObject.Find function can be slow, so any scripts that will be contacted
regarding more than one piece of information or function call can have a temporary local variable to
hold them. This uses less memory than making the variable global to the whole script and cuts down
on access time, making it a compromise between speed and memory use.
In the LevelManager script's ManageLevels function, below the
if (gameState == 1) line, add
1.
// game state must be 2, the game is on
// use the LevelManager's stored values to update and turn on HUD stuff
GameObject.Find("Game Manager").GetComponent<ScoreKeeper>().currentBunCount = bunCount;
// update the zombie bunny count in the HUD
GameObject.Find("Bunny Count").GetComponent<GUIText>().text = bunCount.ToString ();
// manage the battery HUD
BatteryHealth batteryHealth = GameObject.Find("Battery Life").GetComponent<BatteryHealth>();
batteryHealth.batteryRemaining = batteryRemaining;
batteryHealth.trackingBattery = true; // restart the drain
// turn on battery sprites again
GameObject.Find("Garden HUD").GetComponent<ChildVisibility>().SpriteToggle(true);
GameObject.Find("Camera GUI").GetComponent<GUILayer>().enabled= true; // activate GUI Text
2.
Save the script, and save the scene.
3.
Click Play from the StartMenu scene.
4.
Once in the garden, shoot until about 10 zombie bunnies remain, and then
access the Main Menu by pressing F1.
5.
Experiment with the submenus and then press Resume Game.
 
Search WWH ::




Custom Search