Skip to content

Instantly share code, notes, and snippets.

@deadasadodo
Created May 15, 2022 05:31
Show Gist options
  • Save deadasadodo/ea071b081f39cfd3bf5b3c5aed55ec61 to your computer and use it in GitHub Desktop.
Save deadasadodo/ea071b081f39cfd3bf5b3c5aed55ec61 to your computer and use it in GitHub Desktop.
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