using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flashlight : MonoBehaviour {
[Header("Unity Setup")]
public new Light light;
public FlickeringLights flickerLights;
[Header("Variables")]
public float ranAmpMin = .1f;
public float ranAmpMax = 1f;
public float minWaitTime = 30f;
public float maxWaitTime = 90f;
public float waitTime = 5f;
void Start()
{
flickerLights = GetComponent<FlickeringLights>();
StartCoroutine(FlickerTime());
}
void Update () {
flickerLights.amplitude = Random.Range(ranAmpMin, ranAmpMax);
if (Input.GetKeyDown(KeyCode.F))
{
light.enabled = !light.enabled;
}
if (Input.GetKeyDown(KeyCode.L))
{
flickerLights.enabled = false;
light.color = new Color32(255, 234, 114, 255);
StartCoroutine(FlickerTime());
}
}
IEnumerator FlickerTime()
{
yield return new WaitForSeconds(Random.Range(minWaitTime, maxWaitTime));
flickerLights.enabled = true;
StartCoroutine(WaitTime());
}
IEnumerator WaitTime()
{
yield return new WaitForSeconds(waitTime);
flickerLights.enabled = false;
light.enabled = false;
}
}
Here is the code I have so far to activate the flashlight and also activate the flicker and shut off timer.