Hi I’m new to unity coding and I’ve wrote this code to switch the light smoothly with pressing the button,
but my problem is my bool (alarmON) won’t turns to false after the process,
would you please help me to make it works great
thank you
Here is my code:
public float intensityfadeSpeed = 2f;
public float highIntensity = 2f;
public float highStrength = 1f;
public float shadowFadeSpeed = 2f;
public bool alarmOn = false;
void Awake ()
{
GameObject.Find("Directional light").GetComponent<Light>().intensity = 0f;
}
void OnClick()
{
alarmOn = true;
}
void Update () {
if (alarmOn == true)
{
GameObject.Find("Directional light").GetComponent<Light>().intensity = Mathf.Lerp (GameObject.Find("Directional light").GetComponent<Light>().intensity, highIntensity, intensityfadeSpeed * Time.deltaTime);
GameObject.Find("Directional light").GetComponent<Light>().shadowStrength = Mathf.Lerp (GameObject.Find("Directional light").GetComponent<Light>().shadowStrength, highStrength, shadowFadeSpeed * Time.deltaTime);
stopChanging();
}
}
void stopChanging ()
{
if (GameObject.Find ("Directional light").GetComponent<Light> ().intensity == highIntensity && GameObject.Find ("Directional light").GetComponent<Light> ().shadowStrength == highStrength)
{
Debug.Log("bullsEye");
alarmOn = false;
}
}
}