- Home /
How to manipulate time in unity?
hi, i'm trying to build time in my game which is 30 seconds inside my game equal to a second in real time. i've try to use the timer script and multiply it with 30 but the timer gone wrong at the 2nd minute..
here's the code which is count for real time :
private var startTime;
var textTime : String;
var myFont : Font;
function Awake() {
startTime = Time.time;
}
function OnGUI () {
var guiTime = ((Time.time - startTime)); //i've try multiply this time with 30
var hours : int = (guiTime / 14400) % 23;
var minutes : int = (guiTime / 120) % 59;
var seconds : int = guiTime % 60;
textTime = String.Format ("{0:00}:{1:00}:{2:00}",hours, minutes, seconds);
GUI.skin.font = myFont;
GUI.Label(Rect(600, 15, 100, 30), "Time : ");
GUI.Label (Rect (600, 40, 100, 30), textTime);
}
i hope someone can help. thanks!
*sorry for my bad english..:p
Answer by Waz · Jul 15, 2011 at 10:01 AM
Your values are wrong. The 120 should be 60. The 14400 should be 3600.
You should also make guiTime an int.
The code should work with the new numbers, and you're free to put any multiplier you like back where you had it.
How much war would a Warwick wick if a warwick could wick war?
Your answer
Follow this Question
Related Questions
How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers
Changing texture after 3s,4s and 5s 2 Answers
Timer jitters? SOLVED 0 Answers
Accurate timing while using timeScale. 1 Answer
Time.timeScale problem 1 Answer