using System.Collections; using UnityEngine; public class EnviroLightning : MonoBehaviour { public void Lightning() { StartCoroutine(LightningBolt()); } public IEnumerator LightningBolt() { GetComponent().enabled = true; float defaultIntensity = GetComponent().intensity; int flashCount = Random.Range(2, 5); for (int thisFlash = 0; thisFlash < flashCount; thisFlash++) { GetComponent().intensity = defaultIntensity * Random.Range(1f, 1.5f); yield return new WaitForSeconds(Random.Range(0.05f, 0.1f)); GetComponent().intensity = defaultIntensity; } GetComponent().enabled = false; } }