【发布时间】:2019-03-16 22:37:12
【问题描述】:
在解决了ReferenceError with my Flash_Light.cs script 之后,我遇到了脚本中的目标灯不闪烁的问题。
Flash_Light 脚本附加到LampPost_A_Blink1,LampPost_A_Blink1 附加了一个灯(称为RedLight),并且该脚本似乎运行良好(没有警告或错误)。但是,灯不会闪烁。
我的脚本是:
using UnityEngine;
using System.Collections;
public class Blink_Light : MonoBehaviour
{
public float totalSeconds = 2; // The total of seconds the flash wil last
public float maxIntensity = 8; // The maximum intensity the flash will reach
public Light myLight;
void Awake()
{
//Find the RedLight
GameObject redlight = GameObject.Find("LampPost_A_Blink1/RedLight");
//Get the Light component attached to it
myLight = redlight.GetComponent<Light>();
}
public IEnumerator flashNow()
{
float waitTime = totalSeconds / 2;
// Get half of the seconds (One half to get brighter and one to get darker)
while (myLight.intensity < maxIntensity)
{
myLight.intensity += Time.deltaTime / waitTime; // Increase intensity
}
while (myLight.intensity > 0)
{
myLight.intensity -= Time.deltaTime / waitTime; //Decrease intensity
}
yield return null;
}
}
进入播放模式时,指示灯保持亮起,而不是正常闪烁。
我该如何解决这个问题? (我有 Unity 2017.2.0f3)
【问题讨论】:
-
老兄,你刚刚连接好你的灯。花点时间自己调试一下。 stackoverflow.com/questions/52765578/…
-
你调用
flashNow函数了吗?在Awake函数的末尾调用它,并使用StartCoroutine(flashNow())调用它,然后查看灯光是否发生变化。 -
@Programmer 它确实改变了 - 现在,灯是关闭而不是打开(但仍然没有闪烁 D: )。