Combining functions from individual classes into 1 abstract class

My Moss Giant and my Spider maintain the same basic navigation function. I don’t want to rewrite it twice but I also want to make sure that if I need to customize my moss giant or spider, I can in their individual classes. We will now begin the process of combining logic from the moss giant that is shared into the main enemy class, leaving the individual specific scripts that inherit to customize the enemy.

First, let’s use a virtual method for movement. Let’s move our variables over from our moss giant to our enemy class.


I’m going to create a custom class that initalizes — or run’s as a start method.

And now I’m moving my functions over making sure that I add “public virtual” to my methods if I need to access them from my other script.

In our script that inherits, we need to make sure we don’t have a start or update method that overrides the abstract class on the enemy class.

Now the enemies will inherit the same behavior while inheriting a class.