x


Switching color of light

I am rather new to Unity, and I was wondering how to smoothly change the color of a light in the Update function. I have tried a few variations of code based on Color.Lerp, but whenever I would, my colors would shoot up to an extremely high number. I don't have that code on me, but it was along the lines of:

light.color = Color.Lerp(colorA,colorB,Update)

colorA and colorB are your basic colors, and Update ranged from Time.time to Time.deltaTime mixed with other variables to try to get increment from 0 to 1.

What can I do to get the colors to fade from one to the other?

more ▼

asked Dec 11 '11 at 06:32 AM

LokiFirebringer gravatar image

LokiFirebringer
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Here's one approach. I haven't compiled the code so not sure if it contains spelling errors.

var colorA : Color;
var colorB : Color;

function DoLerp (duration : float) {
   var startTime = Time.time;
   while (Time.time - startTime < duration) {
      var amount = (Time.time - startTime) / duration;
      light.color = Color.Lerp (colorA, colorB, amount);
      yield;
   }
   light.color = colorB;
}
@script RequireComponent (Light)
more ▼

answered Dec 11 '11 at 07:24 AM

Daniel 6 gravatar image

Daniel 6
541 2 4 17

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3454
x506
x425
x379
x158

asked: Dec 11 '11 at 06:32 AM

Seen: 1060 times

Last Updated: Dec 11 '11 at 07:24 AM