- Home /
Question by
FLASHDENMARK · Mar 01, 2011 at 08:15 PM ·
colorpointlight
Change color of "Point light" at runtime
Hello everyone.
Is there a way to change the color of a point light at runtime?
Fx from a red color to a green at runtime through script
Thank you very much
;)
Comment
Best Answer
Answer by tool55 · Mar 01, 2011 at 08:48 PM
Here's a link to the scripting manual that deals with this issue:
http://unity3d.com/support/documentation/ScriptReference/Light-color.html
Answer by Rs · Sep 25, 2012 at 05:16 PM
Hello, have a play with this! Just attach the script to an object and attach a light into the field. Hope it helps.
using UnityEngine;
using System.Collections;
public class LightController : MonoBehaviour {
public int lightFactor = 0;
// Light that should be controlled by the LightController
public Light controlledLight01 = null;
void Start () {
}
void Update () {
if(controlledLight01!=null) { // If we have a light as a field
Light l = controlledLight01.GetComponent<Light>(); // Get the Light component
Color c = new Color();
c.r= 1f - lightFactor / 100f;
c.g= lightFactor / 100f;
//c.b= lightFactor / 100f;
c.a=1f;
l.color = c;
}
}
}