Menu
CoddyTech

Waves of Enemies

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 54 of 64.

challenge icon

Challenge

Medium

Send the enemies in waves.

  1. In WaveSet.cs, add a [System.Serializable] class Wave with public Enemy enemy, count and spacing.
  2. Give WaveSet [CreateAssetMenu], public List<Wave> waves and public float restBetweenWaves.
  3. In WaveSpawner, a coroutine from Start loops the waves forever: add 1 to Wave, log Wave 1, spawn enemy i at spawnPoints[i % spawnPoints.Length] every spacing seconds, then rest.

Press Play: grunts, then dashers. Then Check.

Try it yourself

using UnityEngine;

public class WaveSpawner : MonoBehaviour
{
    [SerializeField] private WaveSet waveSet;
    [SerializeField] private Transform[] spawnPoints;

    public int Wave { get; private set; }

    // A later lesson fills this in: sends the waves into the arena.
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground