Highscore system not working! PlayerPrefs.SetInt Problem.


I am new to Unity and coding in general and I would appreciate some help with my game. I currently have a score and highscore system. At present, I have a score system that works fine, however, the highscore system does not seem to work. At the moment my highscore just displays my score. When I look at regedit, I can’t find the file where my highscore should be saved.

This is what makes me think there is a problem with PlayerPrefs.GetInt/SetInt

Any thoughts?

Thanks in advance.

P.S I am also not sure why I need the line texths = GetComponent(); , but it doesn’t work without.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Highscore : MonoBehaviour {

public static int highscore;

Text texths;

// Use this for initialization
void Start () {

	texths = GetComponent<Text>();

	if (PlayerPrefs.HasKey ("Highscore") == false)
		PlayerPrefs.SetInt ("Highscore", 0);
	highscore = PlayerPrefs.GetInt ("Highscore");

	texths.text = "" + highscore;

// Update is called once per frame
void Update () {

	highscore = Mathf.Max (highscore, Score.score);
	texths.text = "" + highscore;


You don’t set the highscore in the player prefs.

You can do it in the OnApplicationPause for example :

void OnApplicationPause()
    PlayerPrefs.SetInt ("Highscore", highscore);