Home>

I'm making a simple horror video with Unity.
Therefore, I wanted to make the screen reflected in the camera dark, and took the form of covering the camera with a black quad.
From there, I want to make the quad blink and make the screen flicker after it flickers, but I want to change the blinking interval and write the code so that it will eventually stop blinking, so how do I add it? Please tell me. (The image looks like the light bulb disappears.)

The code of the script used for blinking is as follows.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Blinker: MonoBehaviour
{
    public float interval = 0.1f;
    void Start ()
    {
        StartCoroutine ("Blink");
    }
    IEnumerator Blink ()
    {
        while (true)
        {
            var renderComponent = GetComponent<Renderer>();
            renderComponent.enabled =! renderComponent.enabled;
            yield return new WaitForSeconds (interval);
        }
    }
}


By the way, Unity is free and uses 2018.2.1

  • Answer # 1

    If the implementation is such that ticks disappear faster and faster
    Interval should be reduced by a certain rate

    IEnumerator Blink ()
    {
        while (interval>0.0001) // The value is reasonable Try different ways to suit your taste
        {
            var renderComponent = GetComponent<Renderer>();
            renderComponent.enabled =! renderComponent.enabled;
            interval * = 0.85;// The value is appropriate. Try different values ​​below 1. If it is 1, it will just flash.
            yield return new WaitForSeconds (interval);
        }
        // When finished, turn it completely black
        renderComponent.enabled = false;
    }


    It will be an implementation
    If the flickering slows and disappears

    interval * = (number greater than 1);


    You can change it to