Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Light

Script interface for light components.
Read time 9 minutesLast updated 2 days ago

Definition

[RequireComponent(typeof(Transform))]public sealed class Light : Behaviour

Remarks

Use this to control all aspects of Unity's lights. The properties are an exact match for the values shown in the Inspector.
For more information about shadow maps, refer to Shadow Mapping.
Usually lights are just created in the editor, but sometimes you want to create a light from a script:

Examples

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

Property

Description

areaSizeThe size of the area light.
bakingOutputThis property describes the output of the last Global Illumination bake.
bounceIntensityThe multiplier that defines the strength of the bounce lighting.
boundingSphereOverrideBounding sphere used to override the regular light bounding sphere during culling.
colorSpecifies the color emitted by the light.
colorTemperatureThe 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. Additional Resources: GraphicsSettings.lightsUseLinearIntensity, useColorTemperature.
commandBufferCountNumber of command buffers set up on this light (Read Only).
cookieThe cookie texture projected by the light.
cookieSize2DThe size of a directional light's cookie.
cullingMaskThis is used to light certain objects in the Scene selectively.
dilatedRangeThe maximum distance the emitted light might travel from the position of the light. This property does not apply to directional lights.
enableSpotReflectorWether a Spot Light should simulate having a reflector.
flareThe flare asset to use for this light.
forceVisibleForce a light to be visible even if outside the view frustum.
innerSpotAngleThe angle of the spot light's inner cone in degrees.
intensityThe Intensity of a light is multiplied with the Light color.
layerShadowCullDistancesPer-light, per-layer shadow culling distances. Directional lights only.
lightmapBakeTypeThis property describes what part of a light's contribution can be baked (Editor only).
lightShadowCasterModeAllows you to override the global Shadowmask Mode per light. Only use this with render pipelines that can handle per light Shadowmask modes. Incompatible with the legacy renderers.
lightUnitThe unit Light.intensity should be displayed in.
luxAtDistanceHow far away to measure LightUnit.Lux from.
rangeThe maximum distance that light travels from a point of emission. This property does not apply to directional lights.
renderingLayerMaskDetermines which rendering LayerMask this Light affects.
renderModeControls how often the light's contribution is calculated during rendering.
shadowAngleControls the amount of artificial softening applied to the edges of shadows cast by directional lights (Editor only).
shadowBiasShadow mapping constant bias.
shadowCustomResolutionThe custom resolution of the shadow map.
shadowMatrixOverrideMatrix that overrides the regular light projection matrix during shadow culling. Unity uses this matrix if you set Light.useShadowMatrixOverride to
true
.
shadowNearPlaneNear plane value to use for shadow frustums.
shadowNormalBiasShadow mapping normal-based bias.
shadowResolutionThe resolution of the shadow map. Change it to balance shadow visual quality and performance.
shadowsDetermines if this light will cast soft or hard shadows, or not cast shadows at all.
shadowStrengthStrength of light's shadows.
shapeRadiusControls the amount of artificial softening applied to the edges of shadows cast by the Point or Spot light.
spotAngleThe angle of the spot light's cone in degrees.
typeThe type of the light.
useBoundingSphereOverrideSet to true to override light bounding sphere for culling.
useColorTemperatureSet to true to use the color temperature.
useShadowMatrixOverrideSet to true to enable custom matrix for culling during shadows.
useViewFrustumForShadowCasterCullWhether to cull shadows for this Light when the Light is outside of the view frustum.

Methods

Method

Description

AddCommandBufferAdd a command buffer to be executed at a specified place.
AddCommandBufferAsyncAdds a command buffer to the GPU's async compute queues and executes that command buffer when graphics processing reaches a given point.
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.
ResetRevert all light parameters to default.
SetLightDirtySets a light dirty to notify the light baking backends to update their internal light representation (Editor only).

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.