Unity3D制作闪关灯效果
代码段:
public GameObject goFlash;//使用的是SpotLight,也可使用其他的效果灯
public float flashDeltaTime = 0.01f; //闪光时间间隔
public void AutoFlash() //自动闪光调用方法
{
StartCoroutine(Flash());
}
IEnumerator Flash() //自动闪光实现
{
if(goFlash != null)
{
for (int i=0; i < 4; i++)
{
goFlash.SetActive(i%2 == 0);// 开关控制
yield return newWaitForSeconds(flashDeltaTime);
}
}
}