Game Development Reference
In-Depth Information
1.
Open the SpawnBunnies script.
Move the four StartCoroutine lines from the bottom of the Start function to
its own function:
2.
public void StartCountdown () {
int tempLitterSize = litterSize * 3; // increased for first drop only
PopulateGardenBunnies (tempLitterSize); // create new zombie bunny
prefabs in the scene
float tempRate = reproRate * 2; // allow extra time before the first drop
StartCoroutine(StartReproducing(tempRate)); // start the first timer- pass in
reproRate seconds
}
3.
Save the script.
4.
Turn off “Maximize on Play,” and turn off the 2D toggle in the Scene view.
5.
Click Play, and wait to see what happens.
The staging area is quiet and peaceful, and the garden remains zombie-bunny free.
The decision now is when to trigger the rest of the action. If you waited until the Gnomatic Garden
Defender is fully in the garden, having triggered the door open, he could stand outside happily watching
the garden being overrun—a clear dereliction of duty. A better scenario is to consider “game on” as
soon as the gates open. You have the SensorDoor script that opens the doors, but it has no idea what it
is opening them onto. You obviously wouldn't want the game to start if he goes through the wrong door.
The OcclusionManager script, on the other hand, tracks the areas that the Gnomatic Garden
Defender is about to enter, but it does so before the gate is open. Theoretically, the player could
trigger “game on” without ever seeing the garden. So a good solution would be to add some
intelligence to the SensorDoor script.
Remembering that the script can be put on any door, you will want to create a flag that marks it
as a “game on” activator. When it is triggered, you will be turning on the Garden HUD, setting the
trackingBattery flag to true , and triggering the StartReproducing coroutine, so you will want to
create variables to make contact with them.
To activate the various elements, you will use a Boolean variable. False says it can't activate the
“game-on” functionality, and true says it can. Because activation for a particular garden is a one-
time deal, as soon as it is triggered, the state switches to false , or can't activate.
6.
Open the SensorDoors script.
7.
Add the following variables:
// variable that can trigger 'game on'
public bool canActivateGame = false;
//objects that must be informed of the 'game on' state
public GameObject gardenHud; // where the battery sprites are & text controlled
public SpawnBunnies bunnySpawner; // the SpawnBunnies script
public BatteryHealth batteryLife; // the script for the battery charge
(on Battery Life object)
 
Search WWH ::




Custom Search