- Home /
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?
Answer by Borgo · Jan 26, 2011 at 12:53 PM
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; }
Answer by nowhereman · Nov 22, 2010 at 03:15 PM
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
But this have a problem that if you want to ilu$$anonymous$$ate a certain place will not works.
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.
Your answer