How do I save my Highest time using playerprefs?

Hi,

I’m currently working on a endless runner game and im struggling with my high score. I have a timer script that works just fine, but I want to able to save the highest score using playerprefs. Does anyone have a clue on how I can do this?

Here’s my current timer script:

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

public class Timer : MonoBehaviour {

 	public Text timer;
	public float highscore = 0;
	public float seconds = 00;
	public float miliseconds = 00;
	static public float minutes = 00;
	public Canvas canvas;

	void FixedUpdate(){
		if (miliseconds >= 60) {
			seconds++;
			miliseconds = 00;
		}	

		if (seconds >=60) {
			minutes++;
			seconds = 00;
		}   

		if (GameOver.gameover == false) {
			miliseconds += Time.deltaTime * 60;
		}
		timer.text = minutes.ToString ("00") + ":" + seconds.ToString ("00") + ":" + miliseconds.ToString ("00");
	}
}

Hi Joey,

You can save your highscore time just by doing :

PlayerPrefs.SetInt("Minutes", minutes);
PlayerPrefs.SetInt("Seconds", seconds);
PlayerPrefs.SetInt("Miliseconds", miliseconds);

after you’ve done that, and you want to check if your new score is bigger than your saved score do:

int highscoreMins = PlayerPrefs.GetInt("Minutes"); 
int highscoreSec = PlayerPrefs.GetInt("Seconds"); 
int highscoreMilisec = PlayerPrefs.GetInt("Miliseconds"); 

//compare those with your old ones

if(minutes > highscoreMins){
   //new highscore
  SetNewHighscore();
} else if(minutes == highscoreMins){
   if(seconds > highscoreMins){
      //new highscore
     SetNewHighscore();
   }
   if(seconds == highscoreSec){
       if(miliseconds > highscoreMilisec){
      //new highscore
     SetNewHighscore();
      } else {
      //do nothing
      }
   }
}

void SetNewHighscore(){
   PlayerPrefs.SetInt("Minutes", minutes);
   PlayerPrefs.SetInt("Seconds", seconds);
   PlayerPrefs.SetInt("Miliseconds", miliseconds); 
}

hope it helped a bit
more info: