Game Development Reference
In-Depth Information
Summary
In this chapter, you got a chance to expand your working knowledge of prefabs as you created a
couple of enclosed areas for the game's environment using the assets you set up in earlier chapters.
By enclosing the areas so that each was occluded when the player was in the other area, you got
to create a small system for occlusion culling. In doing so, you were introduced to the concept of
arrays to store and manage multiple objects of the same type.
With two areas for the player to travel between, you discovered a drawback of third-person camera
navigation. Any time the character goes into a tight spot or turns too close to a barrier, the camera
could go through the geometry. While the garden's design helped to prevent the latter, the former
needed a solution. To help you solve the problem, you turned to the Distance() function. It allowed
you to set the camera's local z position relative to how close the character was to a gate.
Having worked out the structure and flow of the environment, you turned your efforts to populating
the garden. Using Instantiate , you discovered the joys of Random,Range as you dropped zombie
bunnies into the scene with abandon. You discovered that you could randomize everything from
position, rotation, and even the starting location in the motion clip for each of the instantiated
critters.
Repurposing the instantiating code, you learned how to use a coroutine to delay events while
allowing the rest of the game to go forward. Yield and WaitForSeconds allowed you to add to the
varmint population throughout the game automatically. Splitting up the delay even gave you the
opportunity to warn the player when a population explosion was imminent.
Using nested loops, you discovered that you could let the computer plant the garden for you. The
liberal use of Random.Range once again helped break the monotony of a computer-generated layout.
Finally, to tidy up the large number of clones instantiated into your scene, you learned how to
dynamically parent them so that all could be tucked away in the proper area for occlusion culling
when the Gnomatic Garden Defender traveled from one area to the other.
 
Search WWH ::




Custom Search