- Home /
How to: make changes to a var over real time units instead of frame units? Mathf.Lerp
The following changes the variable myVar each frame, but how do I change it every certain number of milliseconds? Let's say every .1 seconds.
Mathf.Lerp(myVar, 0.0f, 0.5f)
If you use $$anonymous$$athf.Lerp(myVar, 0.0f, 0.5f * Time.deltaTime) you will get a consistent lerp rate no matter what the frame rate.
Answer by Peter G · Dec 29, 2010 at 02:52 PM
Use InvokeRepeating:
var myVar : float;
function Start () { InvokeRepeating("LerpVar", .1, .1); }
function LerpVar { myVar = Mathf.Lerp(myVar, 0.0, someIncrement); }
how do I turn off the invokerepeating once it's gotten to the target desired number?
the other problem, aside from not being able to turn it off... it seems to launch straight to the destination value... doesn't seem to take it's time getting there at all.
Use CancelInvoke() to turn it off. What is your someIncrement? Try a lower value.
Your answer
Follow this Question
Related Questions
change variable name inside IF statement, or add text to it 3 Answers
Time elapsed between variable change? 1 Answer
Time of day script not working 2 Answers
Passing Parameters by Value or by Reference 2 Answers
Yielding for a changing amount of time? 2 Answers