# How should I deal with different enemy types? [closed]

I'm making simple space shooter game for Android in Unity. I want to have different types of enemies (different weapon, stats, movement schemes) and I'm not sure how to do it. I'm quite new to objective programming and I don't really know what classes should I create. I guess I could just make a prefab for every enemy since there won't be many types, but that is not what I'm looking for. I have some ideas:

First of all I'd write an BaseEnemy class and enemy type subclasses that inherit from it.

My first idea is to create those without MonoBehaviour. Then I'd have to make an EnemyScript with MonoBehaviour that I'd add to enemy game object. It'd have a specific subclass object inside, which will set every variable. BaseEnemy would just have undeclared variables and in subclass I'd set particular values. But I'm not sure how to deal with different movement schemes then. I wouldn't be able to put move() function in subclass since it wouldn't have MonoBehaviour, so I'd have to find another way. I might put in EnemyScript every possible scheme and then use correct one depending on some type value, but it doesn't seem like a proper way, does it?

The second idea is to just make a MonoBehaviour BaseEnemy class. Then while creating enemy game object I'd just add correct subclass script (aaand... I'm not sure how to do it :/ )

Could you tell me which one is a better way? Maybe neither of those?

There are many different approaches, with different pros and cons. One good approach here, and the one most suited to Unity's entity/component system, is to simply mix and match different MovementBehavior, AttackBehavior, etc.components on different objects to make different enemies.

However that still runs into this problem you mentioned in your question, so I'm curious for clarification on what you're having a problem with there:

aaand... I'm not sure how to do it :/

Is your problem that you simply don't know how to subclass MonoBehaviour? Because you totally can, just like any other class. Technically you already do, you just might not realize it; the public class MyClass : MonoBehaviour { at the top of most scripts is inheriting from MonoBehaviour.

Thus you can simply make a public class BaseEnemy : MonoBehaviour for your enemies to inherit from, and then make a script public class SpecificEnemy : BaseEnemyfor specific enemies. Now you can just drag the SpecificEnemy script onto gameobjects just like any other component.