using System.Collections; using UnityEngine; public class FlickerLight : MonoBehaviour { public float lampSpeed = 0.1f; public float intens_Speed = 9f; public bool timung; public float minIntens = 0.8f; public float maxIntens = 3.5f; public bool loopEnd; public float range_Speed = 12f; public float minRange = 2.8f; public float maxRange = 13.5f; public Color col_Main = Color.white; public float col_Speed = 1.5f; public Color col_Blend1 = Color.yellow; public Color col_Blend2 = Color.red; private Color refCol; private float intens; private float randomIntens; private float range; private float randomRange; private GameObject lamp; private void Start() { lamp = base.gameObject; intens = lamp.GetComponent().intensity; range = lamp.GetComponent().range; lamp.GetComponent().color = col_Main; StartCoroutine(Timer()); } private void LateUpdate() { if (loopEnd) { StartCoroutine(Timer()); } intens = Mathf.SmoothStep(intens, randomIntens, Time.deltaTime * intens_Speed); range = Mathf.SmoothStep(range, randomRange, Time.deltaTime * range_Speed); lamp.GetComponent().intensity = intens; lamp.GetComponent().range = range; col_Main = Color.Lerp(col_Main, refCol, Time.deltaTime * col_Speed); lamp.GetComponent().color = col_Main; } private IEnumerator Timer() { timung = false; randomIntens = Random.Range(minIntens, maxIntens); randomRange = Random.Range(minRange, maxRange); refCol = Color.Lerp(col_Blend1, col_Blend2, Random.value); yield return new WaitForSeconds(lampSpeed); timung = true; randomIntens = Random.Range(minIntens, maxIntens); randomRange = Random.Range(minRange, maxRange); refCol = Color.Lerp(col_Blend1, col_Blend2, Random.value); yield return new WaitForSeconds(lampSpeed); loopEnd = true; randomIntens = Random.Range(minIntens, maxIntens); randomRange = Random.Range(minRange, maxRange); refCol = Color.Lerp(col_Blend1, col_Blend2, Random.value); yield return null; } }