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:
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:
so when the lives reaches 0 the player dies and spawn manager stops spawning enemies
this will stop the loop of spawning enemies.