Unity3D闪光灯效果的实现代码:
using UnityEngine;
using System.Collections;//定义一个Light类
public class Light : MonoBehaviour {//定义一个时间长度public float duration = 1.0F;//定义一个红色(颜色自取)public Color colorRed = Color.red;//定义一个蓝色(颜色自取)public Color colorBlue = Color.blue;// Update is called once per framevoid Update () {float phi = Time.time / duration * 2 * Mathf.PI;//使用数学函数来实现闪光灯效果float amplitude = Mathf.Cos(phi) * 0.5F + 0.5F;light.intensity = amplitude;float x = Mathf.PingPong (Time.time, duration) / duration;light.color = Color.Lerp (colorRed, colorBlue, x);}
}