Score Question

hello. I’m in doubt in a process to save my score …

Next, i dont need a leaderboard … need to save your own best score in the script … my process:


static var score: int;

var highscore: int;

OnGUI function () { = guiSkin;
    GUI.Label (Rect (screen.width / 2-200, 10, 100, 200), score.ToString ()); = guiSkin;
    GUI.Label (Rect (screen.width / 2-100, 10, 100, 200), highscore.ToString ());


score and marked in another script, the Enemy Collision


var points: int;

OnTriggerEnter function (col: Collider) {

GameController.score + = points;


the score works perfectly

How do I save for the highscore?

thanks for the help

Not sure what you’re trying to do, if you need to set the highscore, something like this should work:

if (score > highscore)
score = highscore;

If you’re trying to save it, you can probaly use PlayerPrefs:

PlayerPrefs.SetInt("Highscore", highscore);


highscore = PlayerPrefs.GetInt("Highscore", highscore);

i got solution on this tutorial : Unity tutorial - Pong Game - How To Make Mobile Games - part 5C - YouTube

thanks martin finch !!!