Version: 2022.2
public float spotAngle ;

描述

光的聚光灯锥体的角度(以度为单位)。

这主要用于 Spot 光,对 Point 光不起作用 另请参阅:Light component

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); } } }