- Home /
Material lerp problem
Hello,
I have this script to fae from one material to another, but it doesn't work. nay help?
Also, how I make this to happen once, when I press a key?
Could you please post your current code, with the "code sample" option in the post editor? That will help us, help you.
Never $$anonymous$$d, I changed it. Left only how to fade the two textures when I press a button.
var duration = 2.0;
var dry : boolean;
function Update ()
{
if(dry)
{
var lerp = Time.time / duration;
renderer.material.SetFloat( "_Blend", lerp );
}
}
Answer by robertbu · Jul 08, 2013 at 07:15 PM
Time.time will be the time since the app started, so if Time.time is greater than 2.0 when 'dry' becomes 'true', then nothing will happen with this code. As a quick test, you can change your code to:
var lerp = (Time.time % duration) / duration;
But the real fix will like be some sort of timer that you can start and reset:
timer += Time.deltaTime;
var lerp = timer / duration;
Thanks, it worked! But what if the timer is left for lots of hours? Would that affect the FPS of the game?
No, nothing in the code above will bring down the FPS if run for hours.