I’ve tried implementing some alarm lights in my game, that when set off, alternate in intensity. The problem is that they just stay static, not gettting more or less intense, whats wrong with my code? (c#)
`using UnityEngine;
using System.Collections;
public class AlarmLight : MonoBehaviour
{
public float fadeSpeed = 2f;
public float highIntensity = 2f;
public float lowIntensity = 0.5f;
//public float changeMargin = 0.2f;
public bool alarmOn = true;
private float targetIntensity;
void Awake()
{
light.intensity = lowIntensity;
targetIntensity = highIntensity;
}
void Update()
{
if(alarmOn == true)
{
if(light.intensity == highIntensity)
{
targetIntensity = lowIntensity;
light.intensity = Mathf.Lerp (light.intensity, targetIntensity, fadeSpeed * Time.deltaTime);
}
//CheckTargetIntensity();
else if(light.intensity == lowIntensity)
{
targetIntensity = highIntensity;
light.intensity = Mathf.Lerp (light.intensity, targetIntensity, fadeSpeed * Time.deltaTime);
}
}
}`