The difference between Time.time and Time.deltaTime
Simple script to put a gameobj change color:
Renderer rend = GetComponent (); rend.material.color = Color.Lerp(Color.white,Color.black,Time.time*0.1f);
Works fine, but
Renderer rend = GetComponent (); rend.material.color = Color.Lerp(Color.white,Color.black,Time.deltaTime*0.1f);
Do not work at all. I'm new to Unity so it's not really clear for me why this not working.
Answer by Dragate · Dec 04, 2017 at 07:58 AM
TIme.time:
The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game.
Time.deltaTime:
The time in seconds it took to complete the last frame (Read Only).
https://docs.unity3d.com/ScriptReference/Time-time.html
https://docs.unity3d.com/ScriptReference/Time-deltaTime.html
Both of your approaches are wrong. The third parameter of lerp functions works for values from 0 (values lower than 0 will be treated as 0) to 1(values greater than 1 will be treated as 1).
If you've played your game for 60 minutes, Time.time will return 3600 and passing that to lerp will return Color.black from the very first frame it is called (no smooth transition).
If your game has a stable framerate, Time.deltaTime is pretty much a constant and passing that to lerp will always return the same Color (there is no transition, it's stuck).
Answer by Dzentsetsu · Dec 05, 2017 at 03:47 PM
Thanks for complete answer. I also wanna mention that reading https://unity3d.com/ru/learn/tutorials/topics/scripting/linear-interpolation
help we fully undestand what you were saying.
Your answer
Follow this Question
Related Questions
Type out text in sync with audioclip 0 Answers
Color.Lerp over HP 1 Answer
Setting slider value over time using C# script? 0 Answers
How to use time, when timeScale is 0? 2 Answers
Milliseconds Timer Question 1 Answer