Search Unity

Adding Highscore and Score to the GameOver Scene

Discussion in 'Scripting' started by Jana1108, Jul 4, 2015.

  1. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Hi, once my game has finished I want the score to roll over and display on the GameOver scene. I also want it to show the best score. How could I do this using unity's new UI Text?
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    I'm not sure how much detail to give without knowing how well you understand unity.

    The quick answer is that you can set the public "text" property.
    Code (CSharp):
    1. UItext.text = "string";
    But there's a catch! You have to include the UnityEngine.UI namespace at the top of your code!
    Code (CSharp):
    1. using UnityEngine.UI;
     
  3. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Yeah I'm only 14 years old so not very experienced so could you please explain in more detail of exactly what to do if possible? I did know about the adding UnityEngine.UI at the top though :) Also I've managed to get the score to count up and work on the game scene but I want to display it on the game over scene when the game ends which is what I'm unsure about.
     
  4. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    So far I've written this and put it on an empty game object in the game over scene. All it does is when the game ends the score labels displays this text " Score: 0" it's always 0 even though the score of the game wasn't. How do I fix it so it shows the players score. This is the code:

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class Highscore : MonoBehaviour {

    public Text scoreText;
    public float score;

    // Use this for initialization
    void Start () {

    scoreText.text = "Score: " + score.ToString();

    }

    // Update is called once per frame
    void Update () {

    }
    }