Version: 2021.1
public Color color ;

描述

光的颜色。

若要修改光强度,可更改光的颜色亮度。 光始终增加照明,因此黑色光与 完全没有光相同。 另请参阅:Light component

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

另一个示例:

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