One thing I noticed and was brought up, is that the spider and MossGiant code is nearly identical (if not completely identical), the reason for this was to prepare us to transition to class inheritance. The goal is we want to learn how to create shared behaviors but at the same time, leaving things flexible enough for individual enemies to have their own special methods if we want to implement them.
We don’t have to obligate all of our enemies to use the shared movement code like with the abstract update class. We can create a virtual method that’s optional. Using override, we can create a completely new movement system should we choose.
Regarding components like the Animator and SpriteRenderer, As long as enemies are created consistently, we can use one Animator variable and one SpriteRenderer variable.
We moved all the code that was similar to the spiders and moss giants into the Enemy class, We’ve gone over this code several times in the past week so this should be very familiar if you’ve been following along:
As you can see, there’s almost no difference! But check this out, look at our spider code!
And the Moss_Giant code!
But yet, look at them both behave normally!
Different enemies inheriting from the same class! This is amazing!