how do i store highscore locally C# (SIMPLE)

hi guys i know this question has been asked already but i was too much of a noob to implement them.

im looking for help storing a highscore(int) locally on a mobile device.

i only need it to store 1 entry(just highscore ,not a leaderboard).
no need for a name entry either,

i just want the INT to be stored.
the simplest form of highscore recording…i’d imagine.

i’ve heard PlayerPrefs is the way to go

i would love some help with this. i have never done anything like this on unity before
i would be many thankful

Yes, use the PlayerPrefs. Its really easy to do, just like this:

void StoreHighscore(int newHighscore)
{
	int oldHighscore = PlayerPrefs.GetInt("highscore", 0);	
	if(newHighscore > oldHighscore)
		PlayerPrefs.SetInt("highscore", newHighscore);
}

@jana1108…You have to Add PlayerPrefs.Save(); after if condition in StoreHighScore() and should call this method in Update()…it should work fine…

Mine is like this and its not working, any help please? :frowning:

public class Score : MonoBehaviour {

public Text txtScore;
public static int score;

public Text txtHighscore;
public static int highscore;
int newHighscore;

void Start (){
	score = 0;
}

void Update (){
	txtScore.text = "Score: " + score.ToString ();
	txtHighscore.text = "Highscore: " + PlayerPrefs.GetInt ("highscore");
	StoreHighscore (newHighscore);
}

void StoreHighscore (int newHighscore)
{
	int oldHighscore = PlayerPrefs.GetInt ("highscore", 0);
	if (newHighscore > oldHighscore) 
	{
		PlayerPrefs.SetInt ("highscore", newHighscore);
		txtHighscore = txtScore;
	}
	PlayerPrefs.Save ();
}

}