Created
May 15, 2022 05:31
-
-
Save deadasadodo/ea071b081f39cfd3bf5b3c5aed55ec61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
public bool isFlickering = false; | |
public float TimeDelay; | |
void Update() | |
{ | |
if (isFlickering == false) | |
{ | |
StartCoroutine(flickeringLight()); | |
} | |
} | |
IEnumerator flickeringLight() | |
{ | |
isFlickering = true; | |
this.gameObject.GetComponent<Light>().enabled = false; | |
TimeDelay = Random.Range(0.01f, 0.5f); | |
yield return new WaitForSeconds(TimeDelay); | |
this.gameObject.GetComponent<Light>().enabled = true; | |
TimeDelay = Random.Range(0.01f, 0.5f); | |
yield return new WaitForSeconds(TimeDelay); | |
isFlickering = false; // to change the speed you add to the random range(0.01f, 0.5f) if you change the number 5 the higher the number the less the flickering | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment