unity 5.6.5f1
在看完7.Stealth秘密行动游戏开发-给游戏添加控制器GameController后,我创建了游戏控制器并添加了相应代码后无法控制警戒灯的闪烁,请问是怎么回事?
AlermLight
public bool alermOn = false;
public float animationSpeed = 1;//变化速度
public static AlermLight _instance;
private float LowIntensity = 0;//警报灯不亮
private float HighIntensity = 1;//警报灯最亮
private float targetIntensity;
//初始化、赋值
void Awake()
{
GetComponent<Light>().intensity = 0f;
targetIntensity = HighIntensity;
//alermOn = true;
_instance = this;
}
// Use this for initialization
void Start () {
}
void Update () {
if (alermOn)
{
GetComponent<Light>().intensity = Mathf.Lerp(GetComponent<Light>().intensity, targetIntensity, Time.deltaTime * animationSpeed);
if (Mathf.Abs(GetComponent<Light>().intensity - targetIntensity) < 0.05f)
{
if (targetIntensity == HighIntensity)
{
targetIntensity = LowIntensity;
}
else if (targetIntensity == LowIntensity)
{
targetIntensity = HighIntensity;
}
}
}
else
{
GetComponent<Light>().intensity = Mathf.Lerp(GetComponent<Light>().intensity, 0, Time.deltaTime * animationSpeed);
}
GameController
public bool alermOn = false;
void Awake()
{
alermOn = false;
}
void Update()
{
AlermLight._instance.alermOn = this.alermOn;
}