New Feature — Enemy Movement

Objective: Introduce a different enemy movement where the enemy comes from the sides of the screen

The game in it’s current state only has the enemy moving downwards. In this article, we will introduce the enemy coming from either side of the screen.

Create New Enemy Prefabs

Duplicate the Enemy prefab, name them accordingly and rename name the original prefab to Enemy-Downwards. We will duplicate an enemy to move left and another to move right.

In the Enemy script, create a new EnemyMovementType enum with the three different movements, Downwards, FromTheLeft & FromTheRight.

Add to the script a variable to store the enemy’s movement type.

Now in the Unity Editor, click on each of the Enemy prefabs and set them appropriately to their postfix.

In the Enemy script, lets enhance the enemy movement to include the logic for moving left or right depending on the Enemy Movement Type.

Let’s drag each enemy prefab to test them out.

Finally, we will destroy the enemy once they move off the left or right of the screen.

If we play the game now, we lose both the enemies off screen that were meant to come in because their are destroy straight away since they already meet the limits. We need to not need to check the boundaries till the enemy enters the screen. Remember to add the call to the Update method.

That did it! Once the enemy enters the screen, the boundary checking starts. In the next article, we will explore provide better feedback in the Ammo UI to display the current and maximum ammo.

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.



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
Jean-Noel Seneque

Jean-Noel Seneque


A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity