Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Light.color

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var color: Color;
public Color color;

Description

The color of the light.

To modify the light intensity you change light's color luminance. Lights always add illumination, so a light with a black color is the same as no light at all. See Also: Light component.

#pragma strict
public class Example extends MonoBehaviour {
	var lt: Light;
	function Start() {
		lt = GetComponent.<Light>();
	}
	// Darken the light completely over a period of 2 seconds.
	function Update() {
		lt.color -= (Color.white / 2.0f) * Time.deltaTime;
	}
}
using UnityEngine;

public class Example : MonoBehaviour { Light lt;

void Start() { lt = GetComponent<Light>(); }

// Darken the light completely over a period of 2 seconds. void Update() { lt.color -= (Color.white / 2.0f) * Time.deltaTime; } }

Another example:

#pragma strict
public class Example extends MonoBehaviour {
	var duration: float = 1.0f;
	var color0: Color = Color.red;
	var color1: Color = Color.blue;
	var lt: Light;
	function Start() {
		lt = GetComponent.<Light>();
	}
	function Update() {
		// set light color
		var t: float = Mathf.PingPong(Time.time, duration) / duration;
		lt.color = Color.Lerp(color0, color1, t);
	}
}
using UnityEngine;

public class Example : MonoBehaviour { // Interpolate light color between two colors back and forth float duration = 1.0f; Color color0 = Color.red; Color color1 = Color.blue;

Light lt;

void Start() { lt = GetComponent<Light>(); }

void Update() { // set light color float t = Mathf.PingPong(Time.time, duration) / duration; lt.color = Color.Lerp(color0, color1, t); } }