Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Comparing Time

$
0
0
I am creating a puzzle game with 90 levels. Each level Has a stopwatch (Below) which tracks the time. Since sec min ext are separate variables and the time is displayed in a String, I don't know how to compare current time with a saved best time. var sec : float = 0; var intsec : int; var minutes = 0; var seconds; var miliseconds : int; var guiTime; var time : String; var startTime; var timerShow : boolean = false; var startTimer : boolean = false; var BestTime = 0; function Start(){ startTime = Time.time; } function Update() { if(Input.anyKey || startTimer == true){ startTime= startTime-Time.time; startTimer=true; sec = sec + Time.deltaTime; intsec = sec; miliseconds = (sec - intsec )* 10; // Here you can use 10 instead of 100. if(intsec < 10){ seconds = "0"+intsec; } else{ seconds = intsec; } if(intsec >= 60){ minutes++; sec=0; } time = minutes + ":" + seconds + ":" +miliseconds; } } function OnGUI() { if(Input.anyKey || timerShow == true){ timerShow = true; GUI.Label (Rect (10, 10, 100, 20), time.ToString()); // GUI.Label (Rect(10,30,100,20), BestTime.ToString()); } }

Viewing all articles
Browse latest Browse all 1875

Trending Articles