Spawning objects
This chapter is a continuation of the previous project, so before we add new elements to the game, let's remind ourselves of the progress so far:
As you can see from Figure 12.1, we have an atmospheric interior hallway scene with Spot Lights and panels that glow. If we play the game, we'll notice that we can look around using our Oculus Rift VR headset.
In our game, we want enemy droids to spawn at regular intervals at spawn points of our choosing. Once spawned, each enemy will wander the level searching for the player, and then attack. This functionality immediately depends on a spawning system, as enemies need to be generated in the scene at a specific location and at a particular interval. The spawning behavior could be achieved using the paired Instantiate
and Destroy
functions for creating and removing objects. These functions are slow, however, and should be avoided as much as possible...