I don't know if this issue is in Unity or in my script, the score work well in scoreText, but in the scorePanel its show before last score like it showing 1 rather than 2; the issue doesn't always appear its appear just in specific moment when my score++ and player die nearly in same time, so here is my script. AddToScore is called with InvokeRepeating, scoreText who show me the correct score, it works well
void AddToScore(){
score++;
scoreText.text = score.ToString ();
mySound.Play();
}
This is when my player Die
void OnCollisionEnter2D(Collision2D other)
{
Time.timeScale = 0;
Die ();
}
void Die (){
Pause.SetActive (false);
Panel.SetActive (true);
GameOverPanel.SetActive (true);
GenerateObstacles.HighScore ();
}
And here is the HighScore from GenerateObstacles
public void HighScore(){
if (score > highScore) {
PlayerPrefs.SetInt ("highScore", score);
highScore = PlayerPrefs.GetInt ("highScore");
scorePanel.text = score.ToString ();
highScorePanel.text = highScore.ToString ();
}
else if (score <= highScore) {
highScore = PlayerPrefs.GetInt ("highScore");
scorePanel.text = score.ToString ();
highScorePanel.text = highScore.ToString ();
}
}
Here is a paint to understand
