I have a UI Text that gives a score based off of how far the player has traveled using this code:
public Transform player;
public Text scoreText;
void Update()
{
scoreText.text = player.position.x.ToString("0");
}
I want to display the value of scoreText on the *GameOver* scene that appears when the player collides with an obstacle. The way I am currently doing this is by using *DontDestroyOnLoad* with the following code:
private void Awake()
{
DontDestroyOnLoad(gameObject);
}
This successfully takes the score and puts it on the next scene. However, when I press a *retry* button to take me back to the previous scene, I now have a duplicate of the score overlapping with the original. In other words, every time I play my game, I get a new copy of the score.
_
Can someone help me find a way to prevent these duplicates from appearing every time I run the game? I only want the original score that keeps going up rather than the score from the last game.
↧