Make a Spawn Manager

Cliff Bailey
Aug 22, 2022

--

Create an Empty Object and name it spawnManager.

Create a new C# script and name it spawnManager.

Drag the script onto the eponymous empty game object, giving it form and meaning.

OPEN THE SCRIPT.

We’re going to implement a Coroutine and WaitForSeconds.

OBJECTIVES:

  • spawn enemies every 5 seconds across a randomX
  • create a coroutine of type IEnumerator — Yield Events
  • while loop — the infinite game loop — continues running so long as the prescribed condition is true — it could be infinite and crash your dang computer
  • but Yield Events act as our pause button

Into the script:

Like dis…

We need the while loop

Within it, our Instantiate command; but we need to reference what we’re instantiating, thus a serialized, private prefab — the _enemyPrefab

And to clean it up:

Moving on!

--

--