Hi,
i have a Baseclass Player, and three Suclasses (Enemy, Teammate, Keeper). Every Subclass needs to know it’s own unique Position with “transform.position” and the Position from the Baseclass. I found some working solutions like: unique Variables per Class (playerPos, enemyPos, etc.) or static private Variables with the name “position” in all 4 Classes with a get Property.
BUT my question is, is there a Way to declare a non-static protected Variable “position” in the Baseclass which the subclasses can use (derive) for their own Positions? And then to compare the Positions in Realtime (void Update)?.
Example:
public class Player : MonoBehaviour {
protected Vector3 position;
void Update() {
Position();
}
protected Vector3 Position() {
position = transform.position;
return position;
}
}
public class Enemy : Player {
if (base.Position().x == this.Position().x) {
// Do something
}
}