Creating Space Wars 2D Part 7 Player Spawn Manager and Using singletons with Unity

Krakendono
3 min readJun 30, 2023

--

Now we will add a spawn manager so that we have enemies to shoot at and increase difficulty.

The script above spawns an enemy every 2 seconds across the screen width where the manager is located. I can change it to match every screen size but this will be for webgl and should be played on one size screen format.

Now we can see if your not eradicating the enemy it can get pretty crazy.

I went ahead and added to the enemy script to have the enemy respawn at the top of the screen if not killed to increase the difficulty of the game.

I created a GameManager to handle talking to all the scripts at one time and let everything know the game is now over. Now when the player dies the enemies stop spawning and they die themselves.

The GameManager script is a singleton so that it doesn’t need to be found or applied in each inspector object when it is created.

The ifs can be cleaned up to one if statement by adding a &&

The enemyManager script, enemy script, and the health script have all been updated to know when the player dies and then stop everything. I also added on the health script to look for the players tag so that it will know to turn the game off since both enemies and players use the same script.

--

--

Krakendono
Krakendono

No responses yet