Implementing spawning
We have created lots of objects in the Editor that define our level, but once the game begins, and according to the Player actions, new objects must be created to better fit the scenarios generated by Player interaction. Enemies might need to appear after a while, or bullets must be created according to the Player input; even when enemies die there's a chance of spawning some power-up. This means that we cannot create all the necessary objects beforehand but should create them dynamically, and that's done through scripting.
In this section, we will examine the following spawning concepts:
- Spawning objects
- Timing actions
- Destroying objects
We will start seeing the Unity Instantiate
function, which allows us to create instances of Prefabs on runtime, such as when pressing a key, or in a time-based fashion, such as making our enemy spawn bullets every certain amount of time. Also, we will learn how to destroy these objects to prevent...