I am working on trying to add a coin system to my game. I have it setup right now so that when the player hits a coin the score text goes up by 1. I have setup a reference in the script, which is attached to the coin, to the score text in my scene. In the game the player can click a button that will switch between two lanes to avoid enemies. These lanes are infinte and in these lanes is where I put the coins. And when a new lane is created the reference to the text disappears from the coin and teh tect does not change. I am not sure why the reference is disappearing.
Here is the coin script that is on the coin
public int scoreToGive = 1;
public Text coinText;
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "Player")
{
AddScore();
}
}
public void AddScore()
{
TheScore.theScore++;
if(coinText != null)
{
coinText.text = TheScore.theScore.ToString();
}
Destroy(gameObject);
}
void Update()
{
coinText.text = GameObject.FindGameObjectWithTag("Ui").ToString();
}
}
Thanks to anyone who can help!