x


Change ambient lighting over time?

Okay, so I'm trying to get the ambient lighting to switch to black (so everything is pitch black) and then fade up to a grayish ambient lighting. I'm not too experienced with programming, so this has been really difficult so far, and I'm left with a headache and little progress. I've been trying to use lerping

var duration : float = 1.0;
var color0 : Color = Color.black;
var color1 : Color = Color.grey;

function Update () {
Debug.Log(RenderSettings.ambientLight);
var t : float = Mathf.PingPong(Time.time, duration) / duration;
RenderSettings.ambientLight = Color.Lerp (color0, color1, t);}
}

But then it keeps lerping between the two colors, and I only want to go through the cycle once. Anyone know anything that would work?

more ▼

asked Oct 29 '10 at 04:13 AM

nowhereman gravatar image

nowhereman
295 19 21 31

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

2 answers: sort voted first

Ok my friend, here is a code that I created for you...
You can set any numbers of colors you want and call SetChangeTime to change the time that the colors will lerps.
In your code, you used the old color to lerps, but you need to use the current color.

private var currentColor    : int = 0;
        var changeTime      : float;
        var colors          : Color[];


function Update () {
    RenderSettings.ambientLight = Color.Lerp (RenderSettings.ambientLight, colors[currentColor], changeTime*Time.deltaTime);


    //this is just to test
    if(Input.GetKeyDown("space")){
        NextColor();
    }

}

function NextColor(){
    if(currentColor>=colors.length-1){
        currentColor = 0;
    }else{
        currentColor +=1;
    }
}

function SetChangeTime(ct : float){
    changeTime = ct;
}
more ▼

answered Jan 26 '11 at 12:53 PM

Borgo gravatar image

Borgo
998 9 13 25

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

I guess to answer my own question, I found out the best way to do this was make a GUI Texture that was completely black and covered the entire screen, then change the alpha value in a for loop to make it look like it was fading in and out. It's a little crude, but it works really well

more ▼

answered Nov 22 '10 at 03:15 PM

nowhereman gravatar image

nowhereman
295 19 21 31

But this have a problem that if you want to iluminate a certain place will not works.

Jan 26 '11 at 12:32 PM Borgo

You're also going to have fillrate problems if you have any mobile applications. You want to avoid geometry of any kind (planes included) that fill up a lot of the screen in a semi-transparent fashion.

Apr 10 '12 at 04:11 AM addo
(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:

x427
x19

asked: Oct 29 '10 at 04:13 AM

Seen: 3001 times

Last Updated: Apr 10 '12 at 04:11 AM