- Home /
Time.time explanation.
Can you explain how to use Time.time, how it work?
cross-reference http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html Greetz, $$anonymous$$y.
Answer by duck · Jan 05, 2010 at 09:50 PM
Time.time simply gives you a numeric value which is equal to the number of seconds which have elapsed since the project started playing.
The value is a 'float', which means that you get exact time including the fraction of the second which is currently elapsing, rather than discrete whole-number seconds.
Time.time is useful for many purposes, and it's often used when comparing the current time against a time stored in a variable, to check how much time has elapsed since a certain moment, or how much time remains until a certain future moment.
A common mistake is to use Time.time as the 3rd parameter for a 'Lerp' function. When using Lerp, you would usually need to use Time.deltaTime instead.
Time.time never changes during the course of a function, so you cannot use it to profile code that takes place inside a single function. Time.time (and Time.deltaTime) only change their value once per frame.
For more information, see the Time.time manual page, and the Time Class manual page which - if you click on each function or property of the class - has examples of how to use each of these things.
When you say Time.time and delta time does not change during a function call, does that include realTimeSinceStartup too? You have given this answer in some other threads too but you never say anything about Time.realTimeSinceStartup.
The main difference betweeen Time.time and Time.realTimeSinceStartup is that the latter is not effected by Time.timeScale. In other words: If you have Time.timeScale = 0.1F, when Time.realTimeSinceStartup = 10F, Time.time would be 1F (10 seconds in "real time" would be equivalent to 1 second of "game time").
Time.realTimeSinceStartup DOES change during a function call.
"A common mistake is to use Time.time as the 3rd parameter for a 'Lerp' function. When using Lerp, you would usually need to use Time.deltaTime ins$$anonymous$$d."
Actually, that's another common mistake which will result in similar but incorrect behaviour, and which will never actually reach the target. Lerp needs a number between 0 and 1, where 0 places the lerped object at the start, 1 places it at the end, and values between put it at some proportion between the two.
See here.
It is funny because unity uses time.time in the example of a lerp
http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Lerp.html
Your answer
Follow this Question
Related Questions
Timescale help 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how to pause time when hit an object 0 Answers