Reputation: 55
i want a timer that doesn't count every second. i want it to run slower
timer = timer + Time.deltaTime;
int itimer = (int)timer;
int minutes = itimer % 60;
int hours = itimer / 60;
string time = hours.ToString() + ":" + minutes.ToString().PadLeft(2, '0');
this is the code now. the clock currently starts at 19:20 and i want the minute counter to go up every 4 seconds or something(i still have to figure the exact timing out). i tried doing "Time.deltaTime*0.9", but the code doesn't work like that. how can i best slow it down with this code? also, when it's 20:00 (or 1200 before conversion) i'd like for something to happen, so i still need access to that number thank you
Upvotes: 0
Views: 463
Reputation: 127603
Likely the problem you had was a casting error when you tried assigning the result back to timer
. This is because by default when you did 0.9
it did it as a double
and your variable timer
was a float. Add a f
to the end of the number to mark it a float and it should work.
timer = timer + Time.deltaTime * 0.9f;
int itimer = (int)timer;
int minutes = itimer % 60;
int hours = itimer / 60;
string time = hours.ToString() + ":" + minutes.ToString().PadLeft(2, '0');
Upvotes: 1