How to set high score and have it displayed

I have a score in my game that increments at certain points! this is working fine but i want a saved high score and unsure how to implement playerprefs as i am still getting to grips with unity and c#! so far i have placed a ui text element in my canvas and this is called High Score: 0 i would like the 0 to hold and save the high score! the working score that increments at the moment is in the update method. i just really dont know how to add the player prefs and add it to the text element on the game screen! using unity 5.3.5

public class Player : MonoBehaviour {

	public string currentColor;

	public float jumpForce = 10f;

	public Rigidbody2D circle;
	public SpriteRenderer sr;

	public Color blue;
	public Color yellow;
	public Color pink;
	public Color purple;

	public GameObject obsticle;
	public GameObject colorChanger;

	public static int score = 0;
	public Text scoreText;

	public static int highScore;
	public Text highScoreText;


	void Start () {

		setRandomColor ();
		circle.isKinematic = true;

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

			if (Input.GetButtonDown ("Jump") || Input.GetMouseButtonDown (0)) 
		    
		    {
			circle.isKinematic = false;
				circle.velocity = Vector2.up * jumpForce;
			}
		
		//scoreText.text = score.ToString ();
		scoreManager();
		hiScoreManager ();
	}

	public void scoreManager(){
		scoreText.text = score.ToString ();
	}

	public void SaveHighScore(){
		highScore = PlayerPrefs.GetInt ("HighScore");
		if (highScore < score) {
			highScore = score;
			PlayerPrefs.SetInt ("HighScore", highScore);
		}
	}

	public void hiScoreManager(){
		highScoreText.text = highScore.ToString ();
	}


	private void OnTriggerEnter2D(Collider2D collision)
	{
		if (collision.tag == "Scored") 
		{
			score++;
			Destroy (collision.gameObject);
			Instantiate (obsticle, new Vector2(transform.position.x,transform.position.y + 7f), transform.rotation);
			return;
		}

		if (collision.tag == "ColorChanger") 
		{
			setRandomColor ();
			Destroy (collision.gameObject);
			Instantiate(colorChanger, new Vector2(transform.position.x,transform.position.y + 7f), transform.rotation);
			return;
		}

		if (collision.tag != currentColor) {
			Debug.Log ("You Died");
			SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
			score = 0;
		}

		if (collision.tag == "Floor") 
		{
			SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
		}
	}

	void setRandomColor()
	{
		int rand = Random.Range (0, 4);

		switch (rand) 
		{
		case 0:
			currentColor = "Blue";
			sr.color = blue;
			break;

		case 1:
			currentColor = "Yellow";
			sr.color = yellow;
			break;
		
		case 2:
			currentColor = "Pink";
			sr.color = pink;
			break;
		
		case 3:
			currentColor = "Purple";
			sr.color = purple;
			break;
		}
	}
}

you should not check the value of score in your update :slight_smile:

you just need a function to set the value of your score.
every time that the player gets score this function should be called.

something like this

                public void scoreManager(){
                  scoreText.text=score;

                          }

every time you get score call this function .dude I’m not good at English but i suppose you need a highScore function.

    public void SaveHighScore(){
             highScore=PlayerPrefs.GetInt ("HighScore");
                  if(highScore<Score){
                    highScore=Score;
                 PlayerPrefs.SetInt ("HighScore",highScore);
                         }

then create another function to put the value of highScore in some text.hope it helps .because it helped me :slight_smile: