Waves of Enemies
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 54 of 64.
Challenge
MediumSend the enemies in waves.
- In
WaveSet.cs, add a[System.Serializable]classWavewith publicEnemy enemy,countandspacing. - Give
WaveSet[CreateAssetMenu],public List<Wave> wavesandpublic float restBetweenWaves. - In
WaveSpawner, a coroutine fromStartloops the waves forever: add 1 toWave, logWave 1, spawn enemyiatspawnPoints[i % spawnPoints.Length]everyspacingseconds, then rest.
Press Play: grunts, then dashers. Then Check.
Try it yourself
using UnityEngine;
public class WaveSpawner : MonoBehaviour
{
[SerializeField] private WaveSet waveSet;
[SerializeField] private Transform[] spawnPoints;
public int Wave { get; private set; }
// A later lesson fills this in: sends the waves into the arena.
}
All lessons in Game Architecture in Unity
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot7State Machines
States as ClassesThe Alert StateA State MachineTransitionsEnemy BrainsThe Knight AttacksRecap: Door States10Project: Arena Survivor
The HeroEnemy Types2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in ReachPractice on your own: Unity playground