Forum Discussion
gabriead
11 years agoHonored Guest
Help: How to detect user input in nested Coroutines?
Hi guys, I am having an issue with detecting when a key was pressed inside some nested Coroutines. What my code does so far is, detecting pairs of GameObjects, then according to the Objects play ...
ryahata
11 years agoHonored Guest
Any particular reason why you are doing this with coroutines?
I think that a simple finite state machine would work here. Here's how I would approach the problem.
You should be able to implement this in the Update() function alone (provided you don't use a coroutine to check if the sound file has finished playing)
Hope this helps!
I think that a simple finite state machine would work here. Here's how I would approach the problem.
- Keep track of a few states (Idle, PlayingSound, WaitingForInput)
- In the Idle state you would look for your pairs of objects. When a pair of objects is found you can play the associated file.
- In the PlayindSound state you would wait for the sound to finish playing and move the WaitingForInput state when playback has completed. There are two ways you could do this.
- Check to see if AudioSource is playing (every Update)
- Start a Coroutine that fires when the sound clip is done.
- In the WaitingForInput state you would look for your key presses. When a valid one is pressed go back to Idle.
You should be able to implement this in the Update() function alone (provided you don't use a coroutine to check if the sound file has finished playing)
Hope this helps!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 1 year agoAnonymous
- 1 year ago