I would like to define variable type and name in the base class like this:
class Element extends Monobehaviour {
var z : int;
}
Then I would like classes which inherit from the base class to retain the variable type and name but assign their own value:
class Gold extends Element {
z = 79;
}
class Silver extends Element {
z = 47;
}
However, this assignment should only affect the instance of the variable within that class, not the base class or other subclasses:
// Element.js
// no value declared but defaults to 0 if attached to gameobject
Debug.Log("z");
// 0
// Gold.js
Debug.Log("z");
// 79
// Silver.js
Debug.Log("z");
// 47
Is there a way to do this in Unity (either through inheritance or other functionality)? I anticipate creating a large number of subclasses and would prefer to have standardized variable names and type declarations for simplicity and convenience without resorting to copy-pasting if possible. Thanks.