Menu
CoddyTech

Waves

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 61 of 71.

challenge icon

Challenge

Medium

Send the hunters in waves from the four spawn points.

  1. Write IEnumerator SendWaves() and start it in Start() with StartCoroutine(SendWaves());.
  2. In it, for each wave from 1 to waves, log "Wave " + wave and spawn wave hunters, hunter i at spawnPoints[i % spawnPoints.Length].position.
  3. After each wave, yield return new WaitForSeconds(waveDelay);.

Press Play: one hunter, then two, then three, 4 seconds apart. Then Check.

Try it yourself

using System.Collections;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [SerializeField] private GameObject hunterPrefab;
    [SerializeField] private Transform[] spawnPoints;
    [SerializeField] private int waves = 3;
    [SerializeField] private float waveDelay = 4f;

    // Send the waves with a coroutine started in Start()
}

All lessons in Physics and Gameplay

Practice on your own: Unity playground