Menu
CoddyTech

Open After the Last Wave

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

This step finishes Arena Escape: forces for the player, velocities for the hunters, waves from a coroutine, damage through a Health script and an exit opened from another script.

challenge icon

Challenge

Medium

Open the exit once the last wave is out.

  1. In Spawner, add [SerializeField] private Exit exit;. The scene puts the Exit pad in it.
  2. In SendWaves(), after the for loop, call exit.Open();.

Press Play, survive the three waves and run to the green exit. 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;

    void Start()
    {
        StartCoroutine(SendWaves());
    }

    IEnumerator SendWaves()
    {
        for (int wave = 1; wave <= waves; wave++)
        {
            Debug.Log("Wave " + wave);
            for (int i = 0; i < wave; i++)
            {
                Transform point = spawnPoints[i % spawnPoints.Length];
                Instantiate(hunterPrefab, point.position, Quaternion.identity);
            }
            yield return new WaitForSeconds(waveDelay);
        }
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Physics and Gameplay

Practice on your own: Unity playground