Waves
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 58 of 63.
Challenge
MediumThe hunters now come in waves. The scene has no hunters of its own any more, but a Hunter prefab (with your Hunter script) and four spawn points, SP0 to SP3. Keep the player and the hunters from the earlier lessons, and fill in Spawner, on the Spawner object:
- Fields the Inspector sets:
hunterPrefab(aGameObject),spawnPoints(aTransform[]),waves(3) andwaveDelay(4). - In
Start, start a coroutine that sends the waves. - For each wave from 1 to
waves: logWave 1,Wave 2and so on, spawn as many hunters as the wave's number, hunteri(from 0) atspawnPoints[i % spawnPoints.Length], then waitwaveDelayseconds.
Wave 1 comes as the game starts, wave 2 four seconds later and wave 3 four seconds after that: six hunters in all. Press Play and survive the waves, then Check.
Try it yourself
using UnityEngine;
public class Spawner : MonoBehaviour
{
// A later lesson fills this in: waves of hunters, sent by a coroutine.
}
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