- Home /
Burning Effect Lerp Not werking
Hello, I am trying to make a burning effect, this is my code:
var lerpedColor : Color = Color.white;
var Timer = 5.0;
function Update()
{
gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.white, Color.black, Time.time /Timer);
}
When placed on a cube for example, it works great lerping down in 5s, but if I then place it on another cube with the game still runnning it is directly black, and not going from White to black.
I realise that it is in memory somewhere but how can I reset it?
Thanks.
Answer by khalladay · Nov 17, 2013 at 05:54 AM
Just keep track of the value of Time.time at the beginning of the lerp on a specific object. The problem you are experiencing is due to the value of Time.time already being beyond the duration of your lerp when you assign it to the second object, storing the start time of the lerp for that object allows you to essentially "reset" the time value for the purposes of your lerp calculation.
float start = 0.0f;
void StartLerping()
{
start = Time.time;
}
void Update()
{
Color lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start) / duration);
}
Thanks for your responce, but I still cant get it to work, its not lerping at all now? Im not too familiar with .cs im still quite new and only use .js. Is the void StartLerping(), a seperate function call, or is that the same as function Start()? As i said no cs knowledge just yet! thanks again!
StartLerping is a separate function call. You need to call that before you start lerping the color in update.
Having it as a separate call allows you to have objects start lerping at times other than the start of the game, it also will allow you to reset the lerp whenever you want. You could also do something like this if you wanted to not have to call StartLerping on objects that start the scene with your lerp script.
void Update()
{
if (start == 0.0f) start = Time.time;
Color lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start) / duration);
}
Answer by RudeFX · Nov 17, 2013 at 04:37 PM
Thanks a lot everybody, using all of your info I done it like this:
var lerpedColor : Color = Color.white;
var duration = 30.0;
var start = Time.time;
function Update()
{
if (start == 0.0f)
start = Time.time;
gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start ) /duration);
}
Thanks khalladay for pointing out exactly what was going on ;)