Menu
CoddyTech

Waves

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 58 of 63.

challenge icon

Challenge

Medium

The hunters now come in waves. The scene has no hunters of its own any more, but a Hunter prefab (with your Hunter script) and four spawn points, SP0 to SP3. Keep the player and the hunters from the earlier lessons, and fill in Spawner, on the Spawner object:

  • Fields the Inspector sets: hunterPrefab (a GameObject), spawnPoints (a Transform[]), waves (3) and waveDelay (4).
  • In Start, start a coroutine that sends the waves.
  • For each wave from 1 to waves: log Wave 1, Wave 2 and so on, spawn as many hunters as the wave's number, hunter i (from 0) at spawnPoints[i % spawnPoints.Length], then wait waveDelay seconds.

Wave 1 comes as the game starts, wave 2 four seconds later and wave 3 four seconds after that: six hunters in all. Press Play and survive the waves, then Check.

Try it yourself

using UnityEngine;

public class Spawner : MonoBehaviour
{
    // A later lesson fills this in: waves of hunters, sent by a coroutine.
}

All lessons in Physics and Gameplay