Time for action – creating a space spawn
Our last script will populate our space and will be attached to the player's ship, since it is the center of the game world:
To fill our space with the objects, we need to create another script. Name it
SpaceSpawn
.We start it out with two variables. These two define the space within which the new objects will be spawned. They will be created outside the minimum range but within the maximum range.
public float minRange = 200f; public float maxRange = 300f;
Next, we have two variables for controlling the frequency at which objects should be spawned. These will work the same as the ones we used for making the enemy ships shoot at the player.
public float frequency = 0.3f; private float spawnTime = 0;
The final variable for this script, is an array. It is simply a list of all of the objects that can be spawned. We will be filling it in a little bit, when we return to Unity to set it up.
public GameObject[] spawnList = new GameObject[0];
Update
is once again...