Unity Developer — Enemy Variety

In 2021, the idea of games having to be defined with good guys beating up bad guys is long gone. Anyone can make a peaceful game that tells a story, or something with a high score and no violence whatsoever. It is this idea, that will expand the world of gaming even more. That being said, there are still plenty of games with a variety of characters and movement. So let’s see how we can make some of our enemies vary their styles.

When making more types of any main object, like an enemy or a powerup, you don’t want to always write new scripts for each type. There are two options here. You could the original script a public class that newer scripts inherit from or you could make some separating modifications to the first script. Today we are going to go with the latter.

First thing, the easiest part of making a new type different is the look. You can change the sprite, or you could change the size and color. Plenty of options in the Sprite Renderer to make sure it looks different.

Next, we are going to change some code. To differentiate at key points, let’s declare a serialized variable that we can change in the Inspector of each type.

One of our new enemies fires a different weapon than the others. In the method firing weapons, we can use our variable to change the Instantiate call.

Another one of our enemies has a different movement pattern than the others. We are going to use the same technique to make sure they follow their distinct movement.

For those curious, yes, we are using trigonometry to make our enemy move in a curving pattern. To do this, you simply need a ‘frequency’ and ‘amplitude’ or ‘magnitude’ variable and set either the x or y of your movement to this algorithm. Play around with the values on frequency and amplitude and the result is very cool.

Have to be creative in this field. Think of some ways to vary you enemies, helpful characters, powerups, or anything else. The power is yours.