Hi! I got this score script form one of these Forum Questions, and now I want to use playerprefs to save a highscore that will be visible in the GUI only. I’ve tried to do it myself using what I’ve read, but I’m fairly new to this and would really like some help to make it work. It could be completely wrong and I don’t even know. Here’s what I have:
var score = 0;
var bestscore = 0;
var scoreText = "Score: 0";
var HighScore = "Highscore: 0";
var mySkin : GUISkin;
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin") {
Debug.Log("Other object is a coin");
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function SaveHighScore () {
PlayerPrefs.GetIntInt(score);
PlayerPrefs.SaveInt(bestscore);
HighScore = "Highscore: " + bestscore;
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString());
GUI.Label (Rect (10, 30, 500, 200), HighScore.ToString());
}