Search Unity

Help displaying Best Distance in death screen.

Discussion in 'Scripting' started by PJMES, Sep 3, 2018.

  1. PJMES

    PJMES

    Joined:
    Feb 10, 2018
    Posts:
    1
    Hi all. I am trying to have the highest distance covered to be displayed upon death. I have the displayed distance for when they die, just want the system to keep hold and pull the best distance.

    I am not sure what I am missing. It displays "Best Distance: 0m" no matter what. Please see uploaded PDF for full script.

    This is the portion I am putting it. It only should display when the death screen comes up which it does, but doesn't show overall highscore.

    public void HitHazard()
    {
    canMove = false;
    _canMove = false;
    PlayerPrefs.SetInt("CoinsCollected", coinsCollected);
    //deathScreen.SetActive(true);
    deathScreenCoins.text = coinsCollected + " coins!";
    deathScreenDistance.text = Mathf.Floor(distanceCovered) + "m";
    if (distanceCovered > highscore)
    {
    highscore = PlayerPrefs.GetInt("distanceCovered");
    PlayerPrefs.SetInt("highscore", highscore);
    highscoreText.text = "Best Distance: " + highscore + "m";
    }
    StartCoroutine("ShowDeathScreen");
    }
     

    Attached Files:

  2. Nama222

    Nama222

    Joined:
    Jul 25, 2017
    Posts:
    6