I’m pulling my hair out (and I don’t have much hair to spare!). I hate to introduce myself ot this community with a “help me!” post, but well, I’m at an impasse.
I cannot get the below color.lerp function to work correctly. What I’m trying to do is interpolate between two colors based on the current in-game time, to replicate a rising/setting sun lighting effect. I’m loading a vale of 0-60 into the variable MINUTE, and then using that variable to calculate the current t setting for lerp…
I would expect this to display a color interpolated between the two input colors, but the color value I get is simply the first input color.
I am not new to coding, but I am new to unity and the advanced javascript that is going to be required of me. I could stare at the below code (and believe me I have) for hours upon hours and I can’t find anythign wrong with it. Hoping you scripting gurus can shed a little light on this?
private var LerpTime : float = 0.0;
private var currentTime=0;
private var Minute=0;
private var currentcolor=0;
private var nextcolor=0;
function Update () {
currentTime=(GetComponent(GAME_TIMER).currentHour*3600)+(GetComponent(GAME_TIMER).currentMinute*60)+(GetComponent(GAME_TIMER).currentSecond);
Minute=(GetComponent(GAME_TIMER).currentMinute);
sunSetColor();
}
function sunSetColor(){
//Set Sun ColorRamp
dayColor=new Color[24];
dayColor[0]=Color(0.58,0.59,0.76,1);
dayColor[1]=Color(0.58,0.59,0.76,1);
dayColor[2]=Color(0.58,0.59,0.76,1);
dayColor[3]=Color(0.58,0.59,0.76,1);
dayColor[4]=Color(0.58,0.59,0.76,1);
dayColor[5]=Color(0.9,0.52,0.26,1);
dayColor[6]=Color(0.85,0.62,0.46,1);
dayColor[7]=Color(0.55,0.62,0.46,1);
dayColor[8]=Color(0.2,0.67,0.39,1);
dayColor[9]=Color(1,0.97,0.89,1);
.
.
etc
.
.
.
//Set Color
currentcolor=Mathf.Floor(currentTime/3600);
nextcolor=currentcolor+1;
if (nextcolor>23) nextcolor=0;
LerpTime=Minute/60;
sun.light.color=Color.Lerp(dayColor[currentcolor],dayColor[nextcolor],LerpTime);
}