Quantcast
Viewing latest article 5
Browse Latest Browse All 14

Can't save best time in a level

I have a problem making my game saves best time. I have 2 js scripts: timer.js that is my timer, it saves the value of best time when player complets the level public var bestTime : float; var pass: boolean=false; var timepass: String; var timeobj : String; public var best : String; function Start() { totalTime = 600; timeLeft = 0; kill= GameObject.Find("GameObject").GetComponent(Score); if(PlayerPrefs.GetFloat("1BestTime")!=null) {bestTime=PlayerPrefs.GetFloat("1BestTime");} Debug.Log("Best: "+bestTime); } function Update() { timeLeft += Time.deltaTime; var minutes : int = timeLeft / 60; var seconds : int = timeLeft % 60; var min : int =totalTime / 60; var sec : int = totalTime % 60; timepass = String.Format ("{0:00}:{1:00}", minutes, seconds); timeobj = String.Format ("{0:00}:{1:00}", min, sec); var m : int = bestTime / 60; var s : int = bestTime % 60; best = String.Format ("{0:00}:{1:00}", m, s); if(timeLeft > totalTime&&pass==false) {pass=true; Debug.Log("tempo esaurito"); PlayerPrefs.SetString("Livello",Application.loadedLevelName); Application.LoadLevel("lose"); } else {if(kill.killed==201) load(); } } function OnGUI() {GUI.Label(new Rect(Screen.width/2,2,200,20), "Tempo: " +timepass+"/"+timeobj); if(bestTime!=9999) GUI.Label(new Rect(10,Screen.height-25,300,20), "Miglior Tempo: "+best); else GUI.Label(new Rect(10,Screen.height-25,300,20), "Miglior Tempo: --:--"); } function load() { if(timeLeft

Viewing latest article 5
Browse Latest Browse All 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>