Hi, I’m making Sparky Konga, an interactive game application using the DK Bongo controllers (You can watch my Beta test Video Here: Sparky Konga - Beta Test). 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.
Assets/Scripts/UnityOSC-master/BoncoClapScript.cs(35,14): error CS1624: The body of
BoncoClapScript.Update()' cannot be an iterator block becausevoid’ is not an iterator interface type
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?
FYI, there are huge numbers of questions on all the details of yield on here, (When I was a new Unity user I must have asked 20.) Just search for your faster convenience. Also read at unityGEMS.com Also, for extremely simple timers in Unity, just use Invoke() or InvokeRepeating(). There is absolutely no reason to have any involvement with coroutines for very simple Unity programming, no more than you need to be able to write shaderlab for very simple Unity programming.
– FattieI did before I asked this. Couldn't find anything seemingly similar to my problem.
– SuperSparkplugNo, there are perhaps 100 question exactly about this. There are even (incredibly long) excellent tutorials on the topic, since you've started with no knowledge of coroutines etc.
– Fattie