Game Development Reference
In-Depth Information
Figure 7-33. The critters randomly overrunning the garden
Now the main problem appears to be that they all start the animation clip at the same place. Let's
see about randomizing that as well. The clip length is referred to as a unit size, so 1 is 100% of the
animation clip. You will require access to each individual clone's Animator component and will get it
on the fly.
14.
Beneath the rotation code, add the following:
// randomize the animation clip starting point zBunny.GetComponent<Animator>().
Play("Bunny Eat", 0, Random.Range(0.0f,1.0f));
Here you are accessing the Animator component, referring to its Bunny Eat state/clip on the base
layer, 0, and choosing a random place on its (normalized) timeline to start the animation clip.
15.
Save the script, and click Play.
Now the zombie bunnies happily overrun the garden in a much more random state. But wait, there's
moreā€¦
Coroutines as Timers
Everyone knows rabbits are famous for their rapid rate of reproduction. Part of the challenge
of the game will be to destroy the zombie hoard before it can reproduce beyond the Gnomatic
Garden Defender 's ability to stop it. As you probably guessed, the number of zombie bunnies
added each time will be random within a small range. This is the beauty of having created the
PopulateGardenBunnies() function to take a count as an argument. Here's the new part; this time,
you will create a timer that, yes, you guessed it, randomly calls the PopulateGardenBunnies()
function to add to the current zombie bunny population.
 
Search WWH ::




Custom Search