Game Development Reference
In-Depth Information
1. Open the SpawnBunnies script.
In the
PopulateGardenBunnies
function, you
return
immediately if
canReproduce
is
false
. You can't
use
return
inside the coroutine, so if the first
yield return new WaitForSeconds
is running when
the limit is reached, the stork will be cued. You can, however, wrap the code that follows the
yield
statement in a conditional to achieve the same result.
Inside the
IEnumerator StartReproducing
, below the first
yield return new
WaitForSeconds
, add:
2.
if (canReproduce) { // check the status before continuing after the pause
At the bottom of the
IEnumerator StartReproducing
, below the
if
(canReproduce) StartCoroutine(StartReproducing(10f))
line, add the
closing curly bracket and indent the contents.
3.
To be safe, you should prevent the bundle from dropping if the limit is reached while the stork has
the bundle in its beak.
Add another
if (canReproduce) {
line after the second yield line,
yield
return new WaitForSeconds(Random.Range (1f,2f))
.
4.
The
if (canReproduce) in front of the StartCoroutine(StartReproducing
(reproRate))
line is now redundant and can be removed.
5.
6.
Add the closing curly bracket after it.
The last conditional (minus earlier code that was commented out) should look as follows:
yield return new WaitForSeconds(Random.Range (1f,2f)); // finish the adjusted time
if (canReproduce) {
beak.SetBool("Cue the Beak", true);
DropBundle();
StartCoroutine(StartReproducing(reproRate));
}
7. Save
the script.
8. From Garden 1, activate the Plant Zone[s] and click Play.
9. Shoot down to 11 zombie bunnies remaining, and wait for the stork to
fly by before shooting the next
one.
The stork, fully loaded, continues on without dropping his bundle (Figure
9-50
).