Created
August 19, 2019 07:47
-
-
Save VeggieVampire/ea4cc2d07534f947bdad9284809856fc to your computer and use it in GitHub Desktop.
Flickering light script in unity 3D.
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 FlickeringLightScript : MonoBehaviour { | |
Light testLight; | |
public float minFlickerTime = 0.1f; | |
public float maxFlickerTime = 0.04f; | |
public float LightIntensity = 20f; | |
// Use this for initialization | |
void Start () { | |
testLight = GetComponent<Light> (); | |
StartCoroutine (Flashing ()); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
IEnumerator Flashing(){ | |
while (true) { | |
yield return new WaitForSeconds (Random.Range(minFlickerTime,maxFlickerTime)); | |
testLight.intensity = Random.Range(minFlickerTime,maxFlickerTime) * LightIntensity; | |
testLight.enabled = !testLight.enabled; | |
} | |
} | |
} |
Kiranix
commented
Jul 29, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment