The Exit
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 60 of 63.
Challenge
MediumLast 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 logsThe exit is open. - When the player (tagged
Player) enters the open exit, logYou escaped!and deactivate the player. Anything else entering it, or the player entering it while it is closed, does nothing.
Add to Spawner:
- An
Exitfield namedexit. - When the waves coroutine has finished its loop (the last wave and its
waveDelay), callexit.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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall