Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

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

Light

class in UnityEngine

/

Inherits from:Behaviour

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

Description

Script interface for light components.

Use this to control all aspects of Unity's lights. The properties are an exact match for the values shown in the Inspector.

Usually lights are just created in the editor but sometimes you want to create a light from a script:

#pragma strict
public class Example extends MonoBehaviour {
	function Start() {
		// Make a game object
		var lightGameObject: GameObject = new GameObject("The Light");
		// Add the light component
		var lightComp: Light = lightGameObject.AddComponent.<Light>();
		// Set color and position
		lightComp.color = Color.blue;
		// Set the position (or any transform property)
		lightGameObject.transform.position = new Vector3(0, 5, 0);
	}
}
using UnityEngine;

public class Example : MonoBehaviour { void Start() { // Make a game object GameObject lightGameObject = new GameObject("The Light");

// Add the light component Light lightComp = lightGameObject.AddComponent<Light>();

// Set color and position lightComp.color = Color.blue;

// Set the position (or any transform property) lightGameObject.transform.position = new Vector3(0, 5, 0); } }

Properties

areaSizeThe size of the area light (Editor only).
bakingOutputThis property describes the output of the last Global Illumination bake.
bounceIntensityThe multiplier that defines the strength of the bounce lighting.
colorThe color of the light.
colorTemperature The color temperature of the light. Correlated Color Temperature (abbreviated as CCT) is multiplied with the color filter when calculating the final color of a light source. The color temperature of the electromagnetic radiation emitted from an ideal black body is defined as its surface temperature in Kelvin. White is 6500K according to the D65 standard. A candle light is 1800K and a soft warm light bulb is 2700K. If you want to use colorTemperature, GraphicsSettings.lightsUseLinearIntensity and Light.useColorTemperature has to be enabled. See Also: GraphicsSettings.lightsUseLinearIntensity, GraphicsSettings.useColorTemperature.
commandBufferCountNumber of command buffers set up on this light (Read Only).
cookieThe cookie texture projected by the light.
cookieSizeThe size of a directional light's cookie.
cullingMaskThis is used to light certain objects in the Scene selectively.
flareThe flare asset to use for this light.
intensityThe Intensity of a light is multiplied with the Light color.
lightmapBakeTypeThis property describes what part of a light's contribution can be baked (Editor only).
rangeThe range of the light.
renderModeHow to render the light.
shadowBiasShadow mapping constant bias.
shadowCustomResolutionThe custom resolution of the shadow map.
shadowNearPlaneNear plane value to use for shadow frustums.
shadowNormalBiasShadow mapping normal-based bias.
shadowResolutionThe resolution of the shadow map.
shadowsHow this light casts shadows
shadowStrengthStrength of light's shadows.
spotAngleThe angle of the light's spotlight cone in degrees.
typeThe type of the light.

Public Methods

AddCommandBufferAdd a command buffer to be executed at a specified place.
GetCommandBuffersGet command buffers to be executed at a specified place.
RemoveAllCommandBuffersRemove all command buffers set on this light.
RemoveCommandBufferRemove command buffer from execution at a specified place.
RemoveCommandBuffersRemove command buffers from execution at a specified place.

Inherited Members

Properties

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledHas the Behaviour had enabled called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Methods

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the GameObject.

Static Methods

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961