Waves
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 61 of 71.
Challenge
MediumSend the hunters in waves from the four spawn points.
- Write
IEnumerator SendWaves()and start it inStart()withStartCoroutine(SendWaves());. - In it, for each
wavefrom 1 towaves, log"Wave " + waveand spawnwavehunters, hunteriatspawnPoints[i % spawnPoints.Length].position. - After each wave,
yield return new WaitForSeconds(waveDelay);.
Press Play: one hunter, then two, then three, 4 seconds apart. 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;
// Send the waves with a coroutine started in Start()
}
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