Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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