Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

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

Light.spotAngle

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 spotAngle: float;
public float spotAngle;

Description

The angle of the light's spotlight cone in degrees.

This is used primarily for Spot lights and has no effect for Point lights See Also: Light component.

#pragma strict
public class Example extends MonoBehaviour {
	var interval: float = 0.3f;
	var minAngle: float = 10;
	var maxAngle: float = 90;
	var timeLeft: float;
	var lt: Light;
	function Start() {
		lt = GetComponent.<Light>();
		lt.type = LightType.Spot;
		timeLeft = interval;
	}
	function Update() {
		timeLeft -= Time.deltaTime;
		if (timeLeft < 0.0) {
			// time to change!
			timeLeft = interval;
			lt.spotAngle = Random.Range(minAngle, maxAngle);
		}
	}
}
using UnityEngine;

public class Example : MonoBehaviour { // Change spot angle randomly between 'minAngle' and 'maxAngle' // each 'interval' seconds.

float interval = 0.3f; float minAngle = 10; float maxAngle = 90; float timeLeft;

Light lt;

void Start() { lt = GetComponent<Light>(); lt.type = LightType.Spot;

timeLeft = interval; }

void Update() { timeLeft -= Time.deltaTime;

if (timeLeft < 0.0) { // time to change! timeLeft = interval; lt.spotAngle = Random.Range(minAngle, maxAngle); } } }