Created
July 5, 2023 01:16
-
-
Save ExtevaXT/08b7a3417097e5f6d1bfd00bad79dd9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEngine; | |
| using System.Collections; | |
| public class LightFlickering : MonoBehaviour { | |
| public Light lightSource; | |
| public float flickerInterval = 0.01f; // Time interval between flickers in seconds | |
| public float flickerDuration = 3f; // Duration of each flicker in seconds | |
| void OnEnable() | |
| { | |
| StartCoroutine(Flicker()); | |
| } | |
| void Start() | |
| { | |
| StartCoroutine(Flicker()); | |
| } | |
| IEnumerator Flicker() | |
| { | |
| while (true) | |
| { | |
| // Enable the light | |
| lightSource.enabled = true; | |
| // Wait for a random duration within the flicker duration | |
| yield return new WaitForSeconds(Random.Range(0, flickerDuration)); | |
| // Disable the light | |
| lightSource.enabled = false; | |
| // Wait for a fixed flicker interval | |
| yield return new WaitForSeconds(flickerInterval); | |
| if (!enabled) break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment