Saving score and applying highscore (C#)


I have a score script which works great but the thing is i want to implement highscore, which means i have to save my score. The thing is i have looked online but there scripts are so different to mine. Do you think i can implement a highscore to my game so when the scene restarts the highscore stays.


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

public class Player : MonoBehaviour
	public Text countText;
	private int count;
	public Text scoreText;
	private int scount;
	public AudioClip coin;
	public AudioClip enemy;

	void Start ()

		count = 0;
		SetCountText ();
		scount = 0;
		SetScoreText ();

	void update () {

	void OnTriggerEnter2D(Collider2D col) 
		if(col.gameObject.tag == "Coin")
			col.gameObject.SetActive (false);
			AudioSource.PlayClipAtPoint(coin, transform.position);
			count = count + 1;
			SetCountText ();
			scount = scount + 1;
			SetScoreText ();
		} else if (col.gameObject.tag == "Enemy")
			AudioSource.PlayClipAtPoint(enemy, transform.position);
			scoreText.gameObject.SetActive (true);
	void SetCountText ()
		countText.text = " " + count.ToString ();

	void SetScoreText ()
		scoreText.text = " " + scount.ToString ();

You can use player prefs for that. In your Start method load the high score. In your Update method once the score is greater than the high score then save the new score as the high score.

Something like this?

   int Highscore;
        void Start(){
        //Each time the scene starts it will get the Highscore that was stored in the playerPrefs.
        Highscore = PlayerPrefs.GetInt("Highscore",0);
        void Update(){
//if the variable Score from another script is lower or equal to Highscore, 
//set the HighScore tobe equal to the Score.
        if(ScoreScript.Score > Highscore){
        Highscore = ScoreScript.Score;
        PlayerPref.SetInt("Highscore", Highscore);

If the highscore is higher or equal to the Score than the Highscore is equal to the score.
It will then set the int in the PlayerPref. This would safe the highscore.

Here the Scorescript stands for the name of the script where you access Score.
Score is a static public int in that Scorescript. (I didn’t know how you call it in your script so I just called it Score to be direct)