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
MediumOpen the exit once the last wave is out.
- In
Spawner, add[SerializeField] private Exit exit;. The scene puts the Exit pad in it. - In
SendWaves(), after theforloop, callexit.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);
}
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable WallPractice on your own: Unity playground