How do I use PlayerPrefs to save My Score?

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);
}

This is in my player script:

       GameMaster.currentScore += 1;

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

currentScore = PlayerPrefs.GetInt("NameOfFile");

You should check the Key first, if it exist then it will get score value from PlayerPrefs, otherwise will SetInt the PlayerPrefs. Do as following.

         if (PlayerPrefs.HasKey("highScore") )
		{
			if (GameScore.newScore > PlayerPrefs.GetInt("highScore") ) 
			{
				highScore = GameScore.newScore;
				PlayerPrefs.SetInt("highScore", highScore);
				PlayerPrefs.Save();
			}
		}
		else
		{
			if (GameScore.newScore > highScore ) 
			{
				highScore = GameScore.newScore;
				PlayerPrefs.SetInt("highScore", highScore);
				PlayerPrefs.Save();
			}	
		}

		Application.LoadLevel("GameOver");