Menu
CoddyTech

The Exit

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

challenge icon

Challenge

Medium

Last step: the way out. Keep everything from the earlier lessons. A red Exit pad, a trigger, lies by the north wall, and the scene puts it in the Spawner's new exit field.

Fill in Exit:

  • It starts closed.
  • A public method Open() opens it, turns it green (Color.green) and logs The exit is open.
  • When the player (tagged Player) enters the open exit, log You escaped! and deactivate the player. Anything else entering it, or the player entering it while it is closed, does nothing.

Add to Spawner:

  • An Exit field named exit.
  • When the waves coroutine has finished its loop (the last wave and its waveDelay), call exit.Open().

Press Play, survive the waves and escape, then Check.

Try it yourself

using UnityEngine;

public class Exit : MonoBehaviour
{
    // A later lesson fills this in: the way out, open after the last wave.
}

All lessons in Physics and Gameplay