- Home /
Creating time elapsed label, in js?
I'm sure it's really simple, I'm sure ones you've seen it, it comes natural, but I've only been able to find C sharp scripts for it, and can't seem to convert them into working in my javascript interface. I want to create a label in my window that shows how much time has passed since I started the program in hh:mm:ss.
Comment
Answer by Seth-Bergman · Jul 21, 2012 at 07:07 AM
var timer : float;
function Update(){
timer += Time.deltaTime;
}
function OnGUI(){
var minutes = Mathf.Floor(timer / 60).ToString("00");
var seconds = (timer % 60).ToString("00");
GUI.Label(Rect(200,200,200,400),"minutes:" + minutes + " seconds:" + seconds);
}
this is tested
Would just add:
Time.time is the amount of time since the game started - though I prefer this solution as it can be reset
String.Format works in Unity Script and that would give you the ability to have 00:00:00 using a format string of "{0:00}:{1:00}"
Works 100%, easy to setup and understand, thank you Seth.