Merging the Enemy functionality

Simplifying the Enemy AI script for better Optimization

Now that we have completed one enemy set with full animation with Attack and Damage functions, it is time to apply these features for the rest of the enemy types. Since we are already using Abstract classes it is best to incorporate as much class inheritance as we can to streamline scripts.

Checking for Script Similarities:

The very first signs that you will need to incorporate Abstract classes is when there are several scripts that are repeating itself under the same component Type. In this scenario we can see that the Skeleton and the Moss Giant are having several scripts that are overlapping each other such as the sprite flip since all enemies should be facing the player before attacking. Also the Damage method which will control when the enemy is going to play the Hit animation and toggle the In Combat animation bool is repeating itself.

The revised movement method for the Skeleton and Moss Giant after the Merging into the Parent Enemy class

Meanwhile in the parent Enemy script we will paste the facing player script into the movement method.

Placing the sprite flip within the Parent Enemy Movement method

For the Damage method, this will be a special scenario where we don’t have to incorporate the Damage method into the parent enemy class. This is because we will end up losing the ability to identify which enemy the player has collided with. By keeping the Damage Method separate we will be able to customize the individual settings per enemy type without using the override ability.

Remember to always do a double check before importing/merging scripts together just to see if they still work after the merge.




A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Installing Docker on Windows 10 Home

Limit Work In Progress (WIP)

Agile road full of Work In Progress that is blocking the team from achieving a high velocity.

Migrate to Google Cloud DNS Using OctoDNS: Part 2

Micro Frontends: The Power of Microservices Extended to Frontend

Zsh theme powerline not working in VS code for mac(Solved)

How to do indexing in Janusgraph Or Gremlin

Fair Warning to Fellow Scrum Masters

Ambika Joshi on Creating Space for Womxn Creators through Coding with Friends

A screenshot showing three women smiling while the back of a young child appears in the centre of the image. The image appears over a pink and purple background.

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Adding a health powerup to our prototype

Creating a Health Collectible in Unity!


Quick tip — How to set up Occlusion Culling in Unity