Reply To: How would you slow this down so it doesn't flicker as quickly?

Forum Archive How would you slow this down so it doesn't flicker as quickly? Reply To: How would you slow this down so it doesn't flicker as quickly?

#23051
Jonathan Gonzalez
Participant

    You could add in a delay within a while loop. To use the delay within C# you’ll want to use a Coroutine such as:

    IEnumerator LightFlicker()
    {

    while (true)

    {
    lightBulb.intensity = Random.Range(1.5f, 10.5f);
    yield return new WaitForSeconds(1);

    }

    }

    Making sure that you start the coroutine in the Start function:

    void Start ()
    {
    StartCoroutine(LightFlicker());
    }

    So in the Coroutine you flicker the light from the random range value, wait one second then do it again. The “while true” part means that while the condition is true I want you to keep looping through this. That can be replaced with any condition you want to check yourself.