Hello everyone, I have a question that's been troubling me :
In Unity I have 2 scripts : Char1Specs and Char2Specs that both derive from an empty class CharacterSpecs.
He are the 3 scripts :
public class CharacterSpecs : MonoBehaviour {
}
public class Char1Specs : CharacterSpecs {
public const string NAME = "char1";
public const float GROUND_ACCEL = 2.0f;
}
public class Char2Specs : CharacterSpecs {
public const string NAME = "char2";
public const float MAX_SPEED = 10.0f;
}
I have 2 GameObjects called Char1 and Char2 which respectively have the Char1Specs and Char2Specs scripts attached to them. They also both have a PlayerManager script attached to them.
The PlayerManager script has a public variable of type CharacterSpecs to which I attach either Char1 or Char2 depending on which GameObject the PlayerManager script is attached to.
Here is the PlayerManager script :
public class PlayerManager : MonoBehaviour {
public CharacterSpecs character;
}
And then there's another script called PlayerPhysics :
public class PlayerPhysics : MonoBehaviour {
public PlayerManager PM;
private void Move() { Debug.Log(PM.character.NAME) } // Doesn't work
}
How can I make it so that if I pass Char1Specs to the PlayerManager I can have access to his props in PM.character, and same for Char2Specs ?
My goal is to have something super clean like that
Thanks !