I’ve been searching the forums and trying different things but I just can’t seem to get this to work.
I just want to access a public variable from another script. I have a GameManager object with a GameManager script attached to it. I also have a Player object with a PlayerController script.
//GameObject Script
public int life =100;
//PlayerController Script
//references
public GameManager gameManager; //The GameManager game object is connected in the inspector.
void Start()
{
print(gameManager.GetComponent<GameManager>().life);
}
But the print returns a 0 when it should be 100.