Saving a highscore?

Hey! I have finally gotten my first game ever (basically spaceinvaders) to function, just how I want! (yay!) but… I need to add one last thing - I have a “Highscore” that functions, but… it doesn’t save.

Could anyone help me with this? I googled and found some things on UnityAnswers already, but I get an error when trying to call the function that I found that should do it ( to be completely honest, I barely understand the code that’s meant to save it in the first place)

I’ll link my code below -

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

public class highScoreController : MonoBehaviour {

    public Text highScore;
    public GameObject scoreTimer;
    score myScore;
    public int myHighScore;

	// Use this for initialization
	void Start () 
    {
        GameObject scoreTimer = GameObject.Find("scoreTimer");
        myScore = scoreTimer.GetComponent<score>();
        highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();
        //replace next line with save data
        myHighScore = 0;
	}
	
	// Update is called once per frame
	void Update () 
    {
        if (myScore.scoreme > myHighScore)
        {
            myHighScore = myScore.scoreme;
            highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();
            //trying to call function below - getting error....
            StoreHighscore();
        }
 
	}


    // function below is completely copy & paste
    void StoreHighscore(int newHighscore)
    {
        int oldHighscore = PlayerPrefs.GetInt("highscore", 0);
        if (newHighscore > oldHighscore)
            PlayerPrefs.SetInt("highscore", newHighscore);
            PlayerPrefs.Save();
    }

}

You need to compare your current score with highscore (playerpref which in start is 0) if your current score is greator then highscore set the highscore to current score. i.e.

myHighScore=playerprefs.GetInt(“highscore”); // will be zero in start

if (myScore.scoreme > myHighScore)

{

    playerprefs.SetInt("highscore",myScore.scoreme); 
   //your highscore is saved here you can access it anywhere using playerprefs.GetInt("highscore"); 

}

I was having the same problem, The problem here is your asking StoreHighscore(); but then when you refer it void StoreHighscore(int newHighscore) you have a new parameter (in the parenthesis) that wasn’t declared before. The error is telling you ‘I was expecting 0 parameters’. To fix this, add the number of parameters in the parenthesis, in your case it’s StoreHighscore(1);