Yield Script Update Error

Hi, I’m making Sparky Konga, an interactive game application using the DK Bongo controllers (You can watch my Beta test Video Here: https://vimeo.com/63044764). My problem right now is that the internal microphone for the controller, meant to hear clapping, is reacting to hearing and feeling the vibration of me hitting the other parts of the bongo controller. I coded my project so that the mic value = 0 whenever the button is pressed. However, it didn’t work as well as I wanted to because sound and vibration tend to linger a tiny bit. So, I want to make the mic = 0 function last for more than a single frame. I found out about the yield function and tried to use it to make mic = 0 for about 5 seconds as a test (in the end, I only want it to last for around 1/10 or 2/10 of a second).

    if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.JoystickButton1) || Input.GetKeyDown(KeyCode.JoystickButton2) || Input.GetKeyDown(KeyCode.JoystickButton3)) {
    							mic = 0;
    							yield return new WaitForSeconds(5.0f);
    					}

It worked… However then there began to be problems. I stopped my game play test and changed 5.0f to 0.2f. The problem is that now, I get this error.

I don’t understand why it’s saying this. I changed it back to 5.0f, but I still got this error and I keep getting this error every time I try to run my game (if I remove the yield statement, it works as normal). I seems like it has some problem with the Update function, but I can’t seem to figure it out why considering I didn’t touch anything and it seemingly worked once before.

Does anyone have any idea what the issue is here?

It seems that you’re using c# to code your game, which means that you can’t use yield on normal void functions. You have to put your yield function into an iterator block to make it work and call it via startcoroutine.

Would look like this:
to call it:

void Update()
{
   StartCoroutine(ButtonPressed());
}

and your actual code:

IEnumerator ButtonPressed()
{
   // your yield code here: if(Input....)
}

P.S. more info here → IEnumerator