Hello,
I’m trying to make all the lights with a certain tag flicker. So far only one of the lights is currently flickering. Any idea what I’m missing? They all say active.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightFlicker : MonoBehaviour {
public GameObject[] flickeringLights;
Light lights;
public float minFlickerTime = 0.1f;
public float maxFlickerTime = 0.4f;
void Start() {
flickeringLights = GameObject.FindGameObjectsWithTag("FlickeringLight");
for (int i = 0; i < flickeringLights.Length; i++)
{
lights = flickeringLights[i].GetComponent<Light>();
StartCoroutine(Flicker());
}
}
IEnumerator Flicker()
{
while (true)
{
yield return new WaitForSeconds(Random.Range(minFlickerTime, maxFlickerTime));
lights.enabled = !lights.enabled;
}
}
}