Spawning Objects in Unity without the Clutter

With the understanding of coroutines I have now been able to spawn objects within unity on a timed basis. In this instance I have used an empty game object and called it “Spawn_Manager”. Within the spawn manager script I made enemy prefab link by game object:

This will allow me instantiate the enemy. Spawn manager has behaviour attached to it to spawn enemies every 5 seconds. here is what the code looks like:

Coroutine for spawn manager

This coroutine runs while the player is alive. the stopspawning bool will stop the while loop on the death on the player through communicating with player. Within the player script I have a get component which links to:

Player script communicating with Spawn manager

so when the lives reaches 0 the player dies and spawn manager stops spawning enemies

within Spawn manager

this will stop the loop of spawning enemies.

Spawn Manager in action and stopping once player is no more