# Unity doesn't show always the score

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

• If somebody know how to resolve this issue, share it please :D – Markop Oct 17 '15 at 14:13

Looking at this: GenerateObstacles.HighScore (); It's not clear how the class is designed. HighScore() is not declared static. It would look like GenerateObstacle is a static reference, but it is not. One way is to declare a static reference in GeneratedObstacles like this : public static GeneratedObstacles current; then, in Awake(),
void Awake(){ current=this; }
With that, your code would change to : GeneratedObstacles.current.HighScore();