- Home /
Can not use more variables in array?
I have this script: #pragma strict
var duration : float = 1.0;
var color0 : Color = Color.green;
var color1 : Color = Color.yellow;
var color2 : Color = Color.blue;
var color3 : Color = Color.white;
var color4 : Color = Color.red;
function Update () {
var t : float = Mathf.PingPong (Time.time, duration) / duration;
light.color = Color.Lerp (color0, color1, t);
}
In the last line where it says (color0,color1,t) i can't add more of my variable colors to that line. Can someone help me fix it, and tell me why it is like that?
Lerp() only takes two parameters. It linearly interpolates between two values. In order to get an answer, you need to define what you want to happen. If you are trying to fade between color0 to color1, then from color1 to color2, then color2 to color3, and so on, you need to write code to explicitly move from one color pair to the next...and your colors would be better in an array.
What you explained is what i want. But sadly i did not write this script. I do hvae 2 months experience in javascripting, but i couldt find this out so i checked it out on the web. If you could give a example that would be great.
Answer by AnXgotta · Feb 18, 2014 at 04:42 PM
Try to think about it like this...
You need to Lerp from one color to the next. After that is done, you need to put the color you just changed to in first parameter for Lerp and bring in the next color to change to.
Try using the colors in an array.
light.color = Color.Lerp(myColorArray[i], myColorArray[i+1], t);
if(light.color == myColorArray[i+1]){
if(i >= myColorArray.Length - 2){
i = 0;
} else {
i++;
}
}
This will change from one color to the next until the colors have gone through. Then it will restart. If you have an odd number of colors the last one will be skipped.
This should point you in the right direction.
Your answer
Follow this Question
Related Questions
Assigning GUITexture through Javascript 1 Answer
Popular Color/Light Bleeding Effect 0 Answers
Why change the light color so fast? 2 Answers