- Home /
Pause game while sound plays
In my current project, I am presenting the player with a dialog tree. When the player selects an answer, the game should play a sound file (which is a reading of the answer) and then move on to the next node in the tree. I want the sound to play completely before moving on.
The questions and answers are presented using OnGUI. I've been trying to work with WaitForSeconds() to work in the pause, but it's not quite working. Because I can't use yield in OnGUI, I have a function to handle the sound playback:
function handleResponse (response : int) {
audio.clip = Resources.Load(nodes[nodeloc][3][response][2]);
audio.Play();
yield WaitForSeconds(.5);
nodeloc = nodes[nodeloc][3][response][1];
}
This doesn't work. The game pauses for the appropriate length of time, but the sound doesn't play. If I comment out the yield statement, the sound plays, but the game doesn't pause.
I've done a lot of research on this, but this is as close as I have come to a solution.
Answer by Justin Warner · Dec 28, 2010 at 10:23 PM
Put the yield in front of the audio.Play()... Also, make sure your player has a sound listener (I believe that's what it's called...), try playing a sound by him to make sure he's RECEIVING the sound first, and if he is, than try what I said before, if he isn't, than you might need the listener...
Thanks for your answer, Justin.
I put the yield in front of audio.Play() and the sound doesn't play at all. It just goes on to the next question in the dialog.
As I noted in my original question, the sound works fine if I don't have the yield in place, so there doesn't seem to be anything wrong with how that's set up.
Thanks again.
I'm sorry... $$anonymous$$aybe simplify the script even further... Their might be something wrong with the line above it... Hope you can figure it out man, sorry again.
Your answer
Follow this Question
Related Questions
Easier Way To Add Sound Via GUI? 2 Answers
Gui Playing Audio Trouble 1 Answer
Why is yield not working for me? 2 Answers