- Home /
audio.clip.length 'hides' my button! yaiks!
I ran into something I cannot yet understand; ere's my problem:
if (GUI.Button (Rect(154,128, 495,72), "", SingleplayerButton)){
audio.PlayOneShot(buttonTap);
yield WaitForSeconds (audio.clip.length);
Application.LoadLevel ("Test");
}
as soon as I add the yield WaitForSeconds (audio.clip.length); line, the buttons stop being rendered. all this is called in a onGui function and its supposed to play the button sound in its full lenght before going on and load the level.
actually I am wrong; its here; function Do$$anonymous$$yFirstWindow (windowID : int) { not in the OnGui function i took the example from the documentation which comes above this one.
Answer by Eric5h5 · Jan 29, 2011 at 10:09 PM
You can't put yield into OnGUI, which (like Update) runs every frame and can't be interrupted. That has to be done in another function.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
play an audio clip from a GUI button 1 Answer
Playing a different audio clip after another has finished 1 Answer
Play Sound when GUI button is pressed. 7 Answers
Audio Play on Touch 1 Answer
How do I run a script when a button is highlighted 3 Answers