Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

HighScore - Timer

$
0
0
Hello, Im trying to make a level completion timer for my game. What Im trying to do is make a string show the time of the level completion, but, the problem is that saving a high score isn't working. It keeps being 00:00:00. I want the shortest time to be the high score. This is my whole script : var highScore : String; var score : String; var guiSkin : GUISkin; var minutes : float; var seconds : float; var miliseconds : float; var levelComplete : boolean = false; function Awake() { } function Update() { score = minutes.ToString("00") + ":" + seconds.ToString("00") + ":" + miliseconds.ToString("100"); highScore = PlayerPrefs.GetFloat("Minutes").ToString("00") + ":" + PlayerPrefs.GetFloat("Seconds").ToString("00") + ":" + PlayerPrefs.GetFloat("Miliseconds").ToString("00"); PlayerPrefs.SetString("HighScore", highScore); miliseconds += 60 * Time.deltaTime; if(miliseconds > 60) { miliseconds = 0; seconds += 1; } if(seconds > 60) { minutes += 1; sesconds = 0; } } function OnGUI() { if(levelComplete == true) { if(seconds < PlayerPrefs.GetFloat("Seconds")) { PlayerPrefs.SetFloat("Seconds", seconds); } if(miliseconds < PlayerPrefs.GetFloat("Miliseconds")) { PlayerPrefs.SetFloat("Miliseconds", miliseconds); } if(minutes < PlayerPrefs.GetFloat("Minutes")) { PlayerPrefs.SetFloat("Minutes",minutes); } } } Thank you for your time. Edit : I forgot to add another script of mine, this one: var scoreBoard : ScoreBoard; function Awake() { scoreBoard = GameObject.FindWithTag("Player").GetComponent(ScoreBoard); } function OnCollisionEnter (col : Collision) { if(col.collider.gameObject.tag == "Player") { scoreBoard.levelComplete = true; Time.timeScale = 0; } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles