displaying high score
I using scoreManager script and it works but i couldn't add high score section. In fact I added but it doesn't work. how can i do this high score section. my score script is below.
ScoreManager Script:
public static int score; // The player's score.
Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
// Reset the score.
score = 0;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score;
}
Are you getting an error? What is the problem you're seeing?
I don't get any error. I mean in this score$$anonymous$$anager script, showing score but i couldn't show high score. no problem in the score. i tried playerprefs but it wasn't
in this score$$anonymous$$anager script, showing score but i couldn't show high score. no problem in the score. i tried playerprefs but it wasn't
Answer by Statement · Oct 22, 2015 at 09:52 PM
Create a new Text object in your UI.
Make modifications to your code to add a highscore variable, loading it in awake and updating it if score > highscore.
Finally, set up the reference to your Text object in the inspector.
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
static int highscore;
public static int score;
Text text;
// Set highscoreText up in the inspector.
public Text highscoreText;
void Awake()
{
text = GetComponent<Text>();
score = 0;
highscore = PlayerPrefs.GetInt("highscore");
}
void Update()
{
if (score > highscore)
{
highscore = score;
PlayerPrefs.SetInt("highscore", highscore);
highscoreText.text = "Highscore: " + highscore;
}
text.text = "Score: " + score;
}
}
i have another problem. when i change the font dynamic to unicode or ASCII. it doesn't appaer. what can i do??
Your answer
Follow this Question
Related Questions
how to check how much distance the player covered. 1 Answer
Scoring Points with UI Text 0 Answers
Highscore table C# HELP!!! 0 Answers
Can't score points 1 Answer
Display.displays.Length is count "2". But multi monitor doesn't work! :( 0 Answers