Skip to main content
replaced http://image.noelshack.com/ with https://image.noelshack.com/
Source Link

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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.pnghttps://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

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

![score issue] (https://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

added 7 characters in body; deleted 8 characters in body
Source Link

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 the 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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

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 the player die 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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)

Source Link

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 the player die 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

![score issue] (http://image.noelshack.com/fichiers/2015/42/1444782798-score-issue.png)