As the question states, I want to display and save the player’s best score on the Game Over Scene. And every time the player beats their score, it replaces the previous one.
Here is my Score Script:
#pragma strict
static var currentScore : int = 0;
var offsetY : float = 40;
var sizeX : float = 100;
var sizeY : float = 40;
function Awake()
{
currentScore = 0;
}
function OnGUI () {
GUI.color = Color.yellow;
GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "" + currentScore);
}
PlayerPrefs work by getting and setting values to a file.
To set an int value, use the following function. Name of file being whatever you’d like to call it. This will also overwrite any existing playerpref with the same name
PlayerPrefs.SetInt("NameOfFile", currentScore);
To read a playerpref, say at game startup, use the following function