Nerd For Tech
Published in

Nerd For Tech

Creating a spawning enemy part 2

Now that we have the basics set up for the Spawner and most issues worked out, let’s go further into the methods of fixing it up so that we have our enemies properly using their skills. First off, we will quickly adjust our small enemy in the editor to have the detectors that we placed so that they have the same behaviors as our regular enemies:

Next, with fixing our spawning issue, we need to look at creating a new variable to work with:

As for what we will do with this assignedType, we are going to split our current switch statement into another. This way, we are telling Unity that we are setting the value to a specific number and using that set value into the new statement:

With this new statement set up, we are easing up that statement a little bit and setting it up into a new statement, which in theory, we could move over to our spawn manager script and have it choose the behavior of our ships from there.
With the addition of this new void, we have to go back into our void update and add it into our actions:

From here, we can test to see how it all works:

After doing a quick test, we notice that our spawner is spawning the ships, but now it starts with a bunch of them right off the bat. This seems like a fun challenge and all, but the issue that occurs is sometimes you will get the whole screen filled with enemies and lasers, resulting in death.
To solve this new issue, we need to go into our spawner’s behavior and make a small adjustment.

What was happening before was when the spawner first spawned, it would repeat our code until our spawnerRate caught up to the time.time. This resulted in our enemy spawning countless amounts of minions to attack us, which resulted in 4–5 to maybe 12 or more, all depending on how quickly it spawns. Also, we are going to increase the frequency of our spawn times so that the board doesn’t get overfilled with units. We could set this as a variable and have it be adjusted based on certain circumstances, but that will be something for another time.
Now that we’ve made these adjustments, we can test it out in our game:

So, we now have our dodgers properly dodging our laser, and a spawner is coming in with just 1 ship at a time.

With this in place, we now have a strong base of enemies to deal with rather than the simple enemy. We can adjust the numbers around to figure our what values we want to work with for each enemy, but other than that we can now look towards a couple more features before we can finish up the game.




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium


Basic of Python Decorators

Batch Download Files from AWS S3


Lessons from the Playground

2021, a review of the MIM Swarm

Pooling Connections in Node.js & MySQL

Functional Testing with Loadium & Apache JMeter

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
Jordan Evans

Jordan Evans

More from Medium

Setting up Camera Functionality

Unity camera plugin save image data as bytes

Google Maps & Location Services

Improving Upon Selection Highlighting in Our Game — Part 1