- Home /
Question by
studioglitch · Jul 22, 2017 at 11:12 AM ·
c#lightcolor changecolour
How to slowly change the colour of a directional light object
I need my directional light object to slowly change its color from white to blue. How can i do this in c#? Thanks for help!
Comment
Best Answer
Answer by Getsumi3 · Jul 22, 2017 at 12:15 PM
Hello @studioglitch try this:
public class ColorChanger: MonoBehaviour {
public Light light;
public float r=1;
public float g=1;
public float b=1;
public float smooth = 100;
void Start(){
light.color = new Color(r, g, b);
}
void Update(){
r -= Time.deltaTime/smooth;
g -= Time.deltaTime/smooth;
light.color = new Color (r, g, b);
if (r <= 0) {r = 0; }
if (g <= 0) {g = 0; }
}
}
Answer by UnityCoach · Jul 22, 2017 at 04:36 PM
If you want to do it with code, Gradient is the best interface.
[SerialiseField] Light light;
[SerialiseField] Gradient gradient;
float position;
light.color = gradient.Evaluate (position);
Answer by Bill-Boy17 · Jul 22, 2017 at 12:08 PM
Not possible with an Animation, using c# to activated it?