In my code have an interface damagable
:
public interface Damagable
{
public static float maxHealth { get; set; }
public float currentHealth { get; set; }
}
Different classes implement damagable
, where currentHelath
is unique per instance. The idea was that different instances of a given type would all share the same maxHealth
, to handle things like regeneration and damage based on maxHealth
.
Would the static
keyword here solve the problem?
I could just set maxHealth
in the constructor for each class but I was hoping there would be a way to just make it static per class.
Is there a way to have an interface property to be different on every class that implements it, while each instance of that class has the same value, or is there a better way to do this?
Eventually I'll have multiple classes something like:
public class LargeObstacle : Damagable
{
public float maxHealth { get; set; } = 100;
public float currentHealth { get; set; }
}
public class SmallObstacle : Damagable
{
public float maxHealth { get; set; } = 40;
public float currentHealth { get; set; }
}
And a List<Damagable>
that I can integrate through and get maxHealth
without knowing the classes of each element.