x


Unity3D Game Time

Hi,can someone please help me to make game time in GUI,in this format: ''0:00'' .And it will stop when i die or finish level.Please help.

more ▼

asked Jun 24 '12 at 04:52 PM

Dreatix gravatar image

Dreatix
0 11 14 15

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Updated:

var sec : float = 0;
var intsec : int;
var minutes = 0;
var seconds;
var time;

function Update() {

sec = sec + Time.deltaTime;

}


function OnGUI() {

intsec = sec;

 if(intsec < 10)
 {
  seconds = "0"+intsec;
 }
 else
 {
  seconds = intsec;
 }

 if(intsec >= 60)
 {
  minutes++;
  sec=0;
 }

 time = minutes + ":" + seconds;

 GUI.Label (Rect (10, 10, 100, 20), time);

}
more ▼

answered Jun 24 '12 at 05:02 PM

merry_christmas gravatar image

merry_christmas
3.3k 5 11 17

Nope its not working.

Jun 24 '12 at 05:04 PM Dreatix

If you check your console, the time should be displayed in there. Ok i just updated it, perhaps try again.

Jun 24 '12 at 05:07 PM merry_christmas

I cant modify script because there are too many namespaces and much unexpected errors,i dont know how can i modify script.

Jun 24 '12 at 05:14 PM Dreatix

Can you just please write code correctly,PLEASE! :)

Jun 24 '12 at 05:27 PM Dreatix

Tested the code in unity and made some adjustments, this works correctly now. sorry bout that :)

Jun 24 '12 at 05:30 PM merry_christmas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5099
x3698
x2097
x1964
x573

asked: Jun 24 '12 at 04:52 PM

Seen: 546 times

Last Updated: Jun 25 '12 at 02:33 PM