- Home /
The question is answered, right answer was accepted
animated color: how to smooth?
hi there,
found a script changing skybox-color when pressing a key, which is wonderful. my question now is, how can i smooth this animation with an easing-in/-out?
maybe anyone can help!
here is my code:
var color1 = Color.red; var color2 = Color.blue; var duration = 10;
function Start() { }
function Update () { if (Input.GetKey(KeyCode.Return)) { camera.backgroundColor = color1;
} else {
camera.backgroundColor = color2;
}
}
thank you! andreas
Answer by AliAzin · Jul 31, 2010 at 10:26 AM
You can use
Color.Lerp(color1,color2,blendValue)
which (blendValue = 0 ) means color1 and (blendValue = 1) means color2.
http://unity3d.com/support/documentation/ScriptReference/Color.Lerp.html
then you should smoothly change the blendValue. you can do this with an animation clip or any other method.
Hope that helps.