Nerd For Tech
Published in

Nerd For Tech

2D Shooter: Controlling the Enemy Spawns with the Asteroid

Objective: Initiate enemy and powerup spawns only once the Asteroid is destroyed.

First thing we’re going to do is move the code calling the spawn coroutines in the SpawnManager into their own method so the start method doesn’t start them right away.

Now go to the Asteroid script. Make a variable for the SpawnManager and find it in the start method while also using getcomponent to access the script.

Now call the StartSpawning method right before we destroy the asteroid.

To create a delay we can add “yield return new waitforsecond” in the places where the enemies and powerups are instantiated.

Now we should get a good breather before having to fight any enemies!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sabrina Windsor

Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!