Hi. I’m quite new with Unity and C# but I have previous experience with Java programming (yes Java, not JavaScript). I’m trying to create a “Destructibles” -class which contains functionality for all destructible objects. Now let’s say I have the following piece of code:
public class Destructible : MonoBehaviour {
public float currentHealth;
public Destructible() {
//this is empty
}
public void TakeDamage(float damage) {
currentHealth -= damage;
}
And a class which inherits this:
public class PlayerHealth : Destructible {
public float currentHealth;
public PlayerHealth() {
//this is empty
}
public void TakeDamage(float damage) {
currentHealth -= damage;
}
Now if I remember correctly, this would work just fine in Java (in principle), but when I try this in C#, Unity gives me a following error message: “The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MonoBehaviour) currentHealth”. Isn’t it the idea of inheritance to being able to use the parent’s script as a base for multiple child classes? If so the what is the point of not being able to use item names with them?