Game Development Reference
In-Depth Information
Next you will use the count number to generate some bunnies. You've used a foreach loop to
manage the areas in your OcclusionManager script, but this time you have no pre-existing arrays to
iterate through. You just want to do something a finite number of times, so you will use a standard
for loop.
Wrap the Instantiate code as follows:
5.
for (int i = 0; i < count; i++) {
// create new zombie bunny prefabs in the scene
Instantiate(zombieBunny, new Vector3(Random.Range(minX,maxX), 1.0f, Random.
Range(minZ,maxZ)), Quaternion.identity);
}
6.
Save the script, and press Play.
The ravening hoard creeps slowly forward (Figure 7-32 ).
Figure 7-32. The randomly placed zombie bunnies creeping slowly forward through the garden
You may have noticed that with the addition of the Rigidbody component, the zombie bunnies are no
longer as mobile as they originally were. You could decrease their Mass and Angular Drag, but the
result would not quite be the same. In this case, if they were to continue moving at their animated
pace, many would just end up clustered around the edges of the garden. As zombies aren't terribly
mobile at the best of times, the reduced forward momentum is more of a bonus than a hindrance.
Let's get some more practice with random numbers. Because you never know how many zombie
bunnies might be devouring your garden, it would be fun to populate it with a random number based
on the number that was passed in, count . A good range might be 3/4 of the count to a full count .
 
Search WWH ::




Custom Search