How to inherit from other class in c#?
Hey, I am literally untouched by OOP and also by c# so this question will be rather trivial.
Lets say I want to have 100+ of skills: classes Fireball, Frostbolt, Heal, ... which represent my ingame skills and will be attached to GOs.
I want them all to have some common variables and functions: SkillStart, SkillEnd, SkillInterupt, ...
Normally, I would create common abstract ancestor class for them which would implement those common functions.
But they already inherit from MonoBehaviour so they cannot inherit from another class, right?
Also I have no idea how monobehaviour works behind the scenes so I dont want to do something really dumb.
Answer by jdean300 · Aug 16, 2016 at 11:30 PM
Have your skill base class inherit from MonoBehaviour:
public abstract class SkillBase : MonoBehaviour
{
//put the common variables/functions here
}
public class Fireball : SkillBase
{
//fireball specific stuff here
}
So is it just like that? Wasnt sure whether it wont mess the monobehaviour functionality on children. Really had no idea how the unity magic stuff happens behind scenes. Shouldnt be the SkillBase class abstract?
Yes it should be abstract - but yes it is that simple. Unity doesn't break inheritance.
Your answer
![](https://koobas.hobune.stream/wayback/20220612090951im_/https://answers.unity.com/themes/thub/images/avi.jpg)