您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
30 行
929 B
30 行
929 B
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.Rendering.Universal;
|
|
|
|
[RequireComponent(typeof(Light2D))]
|
|
public class LightIntensityController : MonoBehaviour
|
|
{
|
|
[SerializeField] float minIntensity = 0.0f;
|
|
[SerializeField] float maxIntensity = 0.0f;
|
|
[SerializeField] float minTime = 0.0f;
|
|
[SerializeField] float maxTime = 0.0f;
|
|
|
|
private IEnumerator Start()
|
|
{
|
|
Light2D light = GetComponent<Light2D>();
|
|
|
|
while (true)
|
|
{
|
|
float startIntensity = light.intensity;
|
|
float targetIntensity = Random.Range(minIntensity, maxIntensity);
|
|
float targetTime = Random.Range(minTime, maxTime);
|
|
|
|
for (float t = 0; t < targetTime; t += Time.deltaTime)
|
|
{
|
|
light.intensity = Mathf.Lerp(startIntensity, targetIntensity, t / targetTime);
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
}
|