1

I have the following setup: Entity is deriving from MonoBehaviour. MonoBehaviour implements an implizit conversion to bool. Now if I implement an implicit conversion to bool in Entity, it overrides the one from MonoBehaviour. If I now want to access both the old and the new conversion, I have to do cast back to the base class

public class Entity : MonoBehaviour 
{ 
    private float CurrentHealthPoints { get; set; }

    public static implicit operator bool(Entity entity) 
        => (MonoBehaviour)entity && entity.CurrentHealthPoints > 0;
}

Now my question, is there a different method without having to cast to the base class? I tried to use the base keyword, but couldn't get it to work.

harlekintiger
  • 337
  • 7
  • 22

1 Answers1

1

As far as I know, unless the type being used utilizes contravariance, the explicit casting is inevitable. You can make use of the link too.