- Home /
Question by
isaiahere · May 04, 2013 at 07:17 AM ·
javascriptupdatelightwaitforsecondsflash
Why isn't my flashing script working?
Here is a script that I've made. I want the light to turn on when I press "e" then turn back off in 1 second by itself but I keep getting this error: "Update() cannot be courotine." What is the problem?
function Update () {
if (Input.GetKeyDown("e")) {
if (light.enabled == false)
light.enabled = true;
yield WaitForSeconds(1);
light.enabled = false;
}
}
Comment
Answer by robertbu · May 04, 2013 at 07:24 AM
You can't yield inside Update().
function Update () {
if (Input.GetKeyDown("e"))
Flash();
}
function Flash() {
if (light.enabled == false)
light.enabled = true;
yield WaitForSeconds(1);
light.enabled = false;
}