So i have a simple game and whenever you get a high score i want it to be displayed in the menu. However no matter what score you get that score is always shown , so if the highscore is 20 and you get 5 it displays 5 as the highscore ( whatever score you get).
If you have a solution it would be a ppreciated thanks.
Here are the scripts:
Script that records score and sees if it is higher than the high score:
#pragma strict
public var cube : GameObject;
static var score : int = 0;
var text : Text;
function Awake () {
score = 0;
PlayerPrefs.SetInt("HighScore",0);
}
function Update () {
if (cube == null){
if(score > PlayerPrefs.GetInt("HighScore")){
PlayerPrefs.SetInt("HighScore",score);
}
}
}
function OnTriggerEnter2D(other: Collider2D) {
score +=1;
text.text = "Score : " + score;
}
function Animbr () {
text.GetComponent.<Animation>().Play();
}
And here is the script that displays the high score:
#pragma strict
var text : Text;
function Awake () {
PlayerPrefs.GetInt("HighScore");
}
function Update () {
text.text = "Best Score: " + PlayerPrefs.GetInt("HighScore");
}