Game Development Reference
In-Depth Information
The count and the battery life have been retained, but the zombie bunnies would have originally
been generated the first time the Gnomatic Garden Defender hit the occluder object and triggered
the code from the DoorSensors script.
If you call the same code from the LevelManager, the stored number, bunCount, will be randomized
and therefore changed. Rather than add yet another variable to use as a flag, you can play with
numbers to have the bunCount do double duty as a value and a flag.
1.
Open the LevelManager script.
In the ManageLevels function, just under the GameObject.Find("Bunny Count")
line, add
2.
// repopulate the zombie bunnies and related functionality
SpawnBunnies spawnBunnies = GameObject.Find("Zombie Spawn Manager")
.GetComponent<SpawnBunnies>();
// repopulate the zombie bunnies, adding 100 as a flag not to randomize
spawnBunnies.PopulateGardenBunnies(bunCount + 100); /// repopulate
// restart the drop timer
spawnBunnies.RestartCountdown();
3.
Save the script.
The SpawnBunnies script will require the corresponding changes.
4.
In the SpawnBunnies script, change the protection level on the
PopulateGardenBunnies function:
public void PopulateGardenBunnies (int count) {
Wrap the count = Random.Range and gameManager.SendMessage lines in a
conditional to handle the “100” flag:
5.
if (count < 100) { // check for the resuming game flag
count = Random.Range(count*3/4,count +1); // randomize the count number
// send the amount to update the total
gameManager.SendMessage("UpdateCount",count,
SendMessageOptions.DontRequireReceiver);
}
else count -= 100; // strip off the extra 100, the resume to level flag
Add the RestartCountdown function:
6.
public void RestartCountdown () {
StartCoroutine(StartReproducing(reproRate));
}
7.
Save the script.
8.
Play through from the StartMenu scene.
The correct number of zombie bunnies are dropped.
 
Search WWH ::




Custom Search