Game Development Reference
In-Depth Information
If you were lucky (or skilled) enough to shoot down to 1 zombie bunny before you went out to the
menu, you will have discovered that the canReproduce variable and the battery-tracking flag were
reset to their default values, allowing more zombie-bunny drops after you re-entered the game.
Rather than add two more variables for the LevelManager to track (and all of the associated code),
you will call a little function in to update those values.
In the Level Manager script, ManageLevels function, below the
GameObject.Find("Camera GUI") line, add
1.
GameObject.Find("Game Manager").GetComponent<ScoreKeeper>().StopTheMaddness(bunCount);
2.
Save the script.
3.
In the ScoreKeeper script, add the new function:
public void StopTheMaddness (int bunCount) {
if(bunCount <= stopPopX) {
// stop the battery drain and refresh GUI
BatteryHealth batteryHealth = GameObject.Find ("Battery Life")
.GetComponent<BatteryHealth>();
batteryHealth.trackingBattery = false;
batteryHealth.UpdateBattery();
// stop bun drop
spawner.canReproduce = false;
}
}
4. Save the Script.
To correctly update the battery GUI, you will have to do a little rearranging of the UpdateBattery
function. When it is called from the Update function, the math has already been calculated. You will
be moving the calculations down to the UpdateBattery function so it will be fully self contained.
In the BatteryHealth script, set the UpdateBattery function to public .
5.
In the Update function, move the two lines above the UpdateBattery() line to
the top of the UpdateBattery function.
6.
In the Update function, move the line below the UpdateBattery() line to the
bottom of the UpdateBattery function.
7.
8.
Save the script.
9.
Open the GardenLevel1 scene, and change the GameManager's Stop Pop
X value to 15 so you can quickly test the new code.
10.
Save the scene, and return to the StartMenu.
11.
Play and then access the MainMenu once you have shot enough zombie
bunnies to halt the battery and bunny drops.
The battery remains stopped at its previous charge, and the stork will no longer bring more zombie
bunnies to destroy your garden.
 
Search WWH ::




Custom Search