Creating a Camera Flash

Hi, I have a problem by creating a script that turns an spotlight on and off very fast by clicking the left mouse button. I cant find the error, because there are no ones in the console. Here is my script:

///////////////////////////////////////////////////////////////////////////////////////
var flashlight : GameObject;
var myLight : Light = flashlight.GetComponent(“Light”);

function Start()
{
myLight.enabled = false;
}

function Update ()
{
if (Input.GetKeyDown(KeyCode.Mouse0)){
print(“Klick”);
myLight.enabled = true;
yield WaitForSeconds(1);
myLight.enabled = false;
}

}
/////////////////////////////////////////////////////////////////////////////////////

When I klick the mouse button the message “Klick” doesn’t appear. But when I remove the yield WFS() and myLight.enable = false; the “Klick” appears in the console and the light goes on.

Mfg Zetatron :slight_smile:

Update can’t be a Coroutine, so you can’t use yield there. Put the logic in the if statement in a function instead and call that.

Thank you very much! now it is working :slight_smile:

1 Like