- Home /
The question is answered, right answer was accepted
How can I change the color of a light over time?
If I have two defined colors (public Color earlyMorning = new Color (95f, 59f, 168f, 1f);) ect. How can I change the color of a light over, say, 60 seconds?
I tried light.color += earlyMorning / 60 * Time.deltaTime; however, if I log the color of the light to the console every frame, it only increases the alpha value.
So, what is the most effective method to change the color of the light over time?
Answer by robertbu · Jun 02, 2013 at 04:06 AM
If you Google "Unity3d change color over time", you will find many hits, many with scripts. Here is one:
http://answers.unity3d.com/questions/325568/problem-with-fading-a-colour-over-time.html
Answer by crummyrex · Jun 02, 2013 at 03:59 AM
Just attach this to the camera and set its clear flags to solid color!
var color1 : Color = Color.red;
var color2 : Color = Color.blue;
var duration = 3.0;
// Set clear flags to color
camera.clearFlags = CameraClearFlags.SolidColor;
function Update () {
var t : float = Mathf.PingPong (Time.time, duration) / duration;
camera.backgroundColor = Color.Lerp (color1, color2, t);
}
@crummyrex. This is not going to work. You are not executing anything in a loop.
Answer by PAEvenson · Jun 02, 2013 at 03:09 AM
I would look up color lerping....
http://docs.unity3d.com/Documentation/ScriptReference/Color.Lerp.html
if you need more help understanding the lerp function let me know.
I've never really used any lerp function before, could you give me the rundown?
The link in @robertbu's comment should give you a pretty good idea...I also believe the rgba parameters of the color constructor are between 0 - 1. This might be what is throwing you off. Good luck!
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Change light color smoothly without Lerp ??? 2 Answers
Distribute terrain in zones 3 Answers
Time.deltaTime making color lerp appear fast, but won't reach 1 1 Answer
Lerping 10 collors not that smooth 1 Answer