Noob question about class inheritance

I’m kinda new to scripting and I’ve got a basic question about class inheritance in Unity.

Let’s say I want to make a base class named Enemy, which will contain the basic features shared by all enemies, and a derived class for every enemy type, for example, Orc and Goblin.

So I’ve got three different scripts: Enemy (the parent class), Orc and Goblin. And the question is: to which gameObjects should I attach them? I can only imagine the Orc and Goblin scripts must be attached to the Orc and Goblin prefabs, but where do I put the Enemy class?

Thanks in advance!

Simply put, you don’t put the Enemy class anywhere- it comes with the inheriting classes automatically. Because Orc and Goblin inherit from Enemy, they get access to all the member variables of Enemy in addition to their own specific variables.

For instance, suppose all your enemies have an integer variable health. You can put health into the Enemy base class, and every class that inherits Enemy will get that variable. On the other hand, if only your Goblins have a float variable magic, you would put magic into the Goblin class. Only the Goblins would have that variable.

The answer is: nowhere. The Enemy class is just the base class. Every derived class is also an Enemy. If the Enemy class itself should not be used on it’s own you should make it an abstract class. That way it can’t be attached to a GameObject.