Inheritance help

Hey guys, I’m new to scripting but been trying to get better little by little. Right now I’m kind of confused with something and I’m sure it’s stupid simple but I just don’t see it.

I have the following scripts

public class Ability : MonoBehavior {

    public virtual void HandleAbility ();

}
public class Dash : Ability {

    public override void HandleAbility () {
        // Do Dash
    }

}
public class Player : MonoBehavior {

   public Ability ability;

   void Update () {
      ability.HandleAbility ();
   }

}

Now my issue is that I want to be able to assign the Dash.cs script to the ability variable in Player.cs but I’m not able to do so even when the Dash.cs script is already derived from Ability.cs. Not sure if I’m explaining my self correctly. Please help if you know a fix!

May be just a typo but for Ability you probably mean to put it as abstract:

    public abstract class Ability : MonoBehavior {
    
        public abstract void HandleAbility();
    
    }

If that’s the case it will work.

For you to add ‘Dash’ to a ‘Player’ component, Dash needs to be a component as well. (see my attachment)

3463229--274786--Capture.PNG

Oh I see. I thought there was a way of applying a script as a variable instead of always adding it as a component. Thanks for your help xjjon!