Enemy wave spawner
A wave spawner may sound scary, but it’s just a straightforward script. We need to instantiate a new enemy from a given position and on a fixed (or random) time interval. We’ll also ensure things don’t get out of hand by limiting the number of enemies spawned.
So, with that in mind, let’s have a look at our new EnemySpawner
script – create it in the Assets/Scripts
folder – and see whether you can point out where the few requirements I just stated have been implemented:
using UnityEngine; public class EnemySpawner : MonoBehaviour { [SerializeField] private Enemy _enemyPrefab; [SerializeField] private float _spawnInterval = 5f; [SerializeField] private int _maxSpawned = 3; private int _objectCount = 0; private void Start() => InvokeRepeating( ...