Time for action – creating spawns
The script we will be creating in this section will keep our game world populated with all the enemies our player might want to destroy:
We need another new script for this section. Once created, name it
SpawnPoint
.This script begins simply with a few variables. The first variable will hold a reference to our
EnemyTank
prefab. We need it so we can spawn duplicates.public GameObject tankPrefab;
The second variable tracks the spawned tank. When it is destroyed we will create a new one. Using this variable we prevent the game from becoming overwhelmed with the enemy. There will only be as many tanks as spawn points.
private GameObject currentTank;
The third variable is for setting a distance from the player, to prevent spawning tanks on top of the player. If the player is outside this distance, a new tank can be spawned. If they are within, a new tank will not be spawned.
public float minPlayerDistance = 10;
The first function we will use is
FixedUpdate
. It will...