I am building out a Zelda game and I have ran into an issue -
public void UpdateCoins()
{
Debug.Log(GameManager.instance.currCoins);
//coinsText.text = "Coins " + GameManager.instance.currCoins;
}
That works as expected -
But when I do this...
public void UpdateCoins()
{
Debug.Log(GameManager.instance.currCoins);
coinsText.text = "Coins " + GameManager.instance.currCoins;
}
I receive an Object Reference not set to an instance of the object error.
As you can see it is set. Here is my simple GameManager script
public static GameManager instance;
public int currCoins;
private void Awake()
{
instance = this;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void GetCoins(int coinsToAdd)
{
currCoins += coinsToAdd;
UIManager.instance.UpdateCoins();
}
}
Any thoughts on why this isn't working the way it should?
Thanks!