Automatically disabling, enabling and looping Depth of field

Hi,

i want to automatically disable and then enable Depth of field with looping forever, the script is attached to my main camera. I want the transfer from enabled to disabled position to be smooth and than loops forever.

Is there some preset function in unity, or do i have to somehow implement it in my script manually?

thanks.

ok, i have managed to work it on prressing spacebar, but how do i make it loop? #pragma strict private var myLight : DepthOfFieldScatter; function Start () { myLight = GetComponent(DepthOfFieldScatter); } function Update () { if(Input.GetKeyUp(KeyCode.Space)) { myLight.enabled = !myLight.enabled; } }

1 Answer

1

If you just want to turn it on an off at some interval, see InvokeRepeating().

#pragma strict

private var myLight : DepthOfFieldScatter;


function Start ()
{
    myLight = GetComponent(DepthOfFieldScatter);
    InvokeRepeating("FlipLight", 2.0, 2.0);
}


function FlipLight ()
{
        myLight.enabled = !myLight.enabled;
}

Thanks, that works. Is there any way to make the change smooth? I think i need to somehow implement some variables and make them slowly count to target value and than back to make the change smooth.

Thanks, that works perfectly. Just values are diffrent, i set speed to 0.05, min to 1 and max to 1.2 thanks a lot