Loading & Saving a highscore

Hey - So, I actually already asked this, but I didn’t quite understand, and I’ve spent a fair few hours googling, I’m sure I have missed something basic that I shouldn’t of overlooked - my code for this has gone through quite a few iterations, the best I could do (and I don’t understand why it was doing it) was my Highscore was permanently set to “31” for a reason I couldn’t tell.

I’m attempting to save my highscore so I can keep it each time the game restarts.

This is my code underneath.

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

public class highScoreController : MonoBehaviour {

    public Text highScore;
    public GameObject scoreTimer;
    score myScore;
    public int myHighScore;
	void Start () 
    {
        GameObject scoreTimer = GameObject.Find("scoreTimer");
        myScore = scoreTimer.GetComponent<score>();
        highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();
        myHighScore = PlayerPrefs.GetInt("highs");
	}
	
	// Update is called once per frame
	void Update () 
    {
        if (PlayerPrefs.GetInt("highs") > myHighScore)
        {
            myHighScore = PlayerPrefs.GetInt("highs");
            StoreHighscore();
        }
        else
            highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();

 
	}


    void StoreHighscore()
    {
        if (myScore.scoreme > myHighScore)
        {
            PlayerPrefs.SetInt("highs", myHighScore);
            PlayerPrefs.Save();
        }
    }

}

Sorry for submitting more-or-less the same question twice, but I’m extremely stuck on this…

Yeah, you have a number of problems in the above code…

Basically, you want something like this:

void Start()
{
    // load the stored high-score
    myHighScore = PlayerPrefs.GetInt("highs");
}

void Update()
{
    // if the current score is higher than the previously stored score...
    //   - update the "in-memory" high score
    //   - store the new score as the high-score
    if (Myscore.scoreme > myHighScore)
    {
        myHighScore = Myscore.scoreme
        StoreHighscore();
    }
}

 void StoreHighscore()
 {
     PlayerPrefs.SetInt("highs", myHighScore);
     PlayerPrefs.Save();
 }

The above assumes that the current, running score is available in Myscore.scoreme (which seems to be the case in the original code). While there are some things that could still be cleaned up, that should be pretty close. Though, caution - all of the above was typed directly into the forum and is untested…