Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Help displaying Best Distance in death screen.

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

  1. PJMES


    Feb 10, 2018
    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);
    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";

    Attached Files:

  2. Nama222


    Jul 25, 2017