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;
             
    	
    	        }
    }

1 Answer

1

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;
    }