12 April 2015

Adding a highscore

It's a no brainer that every game involving a score should have a highscore to challenge the player to beat it. Particularly with my prototypes, where the score is the only way to tell how well the player has done, a highscore is indispensable.

Having said that I've done a bit of research to find out how to save a variable even after the application is closed and then re-opened which would enable to save a highscore.

PlayerPrefs.SetInt("variableName", variableName);

and:

PlayerPrefs.GetInt("variableName");

is what I needed. SetInt remembers a variable whereas GetInt retrieves it.

Here's the updated Square code where I put them:
Now it is only a matter of placing the highscore textfield in the top right corner and leave it there for players to compare with their score.

References:
How to save a progress by user with diferent users [ONLINE] Available at: http://answers.unity3d.com/questions/201731/how-to-save-a-progress-by-user-with-diferent-users.html [Accessed 12th April 2015]

Unity Documentation: PlayerPrefs.SetInt[ONLINE] Available at: http://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html [Accessed 12th April 2015]

No comments:

Post a Comment