- Home /
 
 
               Question by 
               oB77 Raptr · May 28, 2015 at 02:21 PM · 
                javascriptuibuttondelay  
              
 
              Delay on button press
i am trying to make it so once a button is pressed it plays a sound before changing scenes. heres my code atm
 #pragma strict
 
 function ChangeToScene(sceneName : String) {
 
   GetComponent(AudioSource).Play();
   Application.LoadLevel(sceneName);
 }
 
 function QuitGame() {
 
   GetComponent(AudioSource).Play();
   Application.Quit();
 }
 
               i want it to play the sound before it switches scenes. thnx
               Comment
              
 
               
              Answer by RSharma98 · May 29, 2015 at 09:12 AM
Use:
 yield WaitForSeconds(x);
 
               where 'x' is the number of seconds you want the delay to be
Answer by karl_jones · May 28, 2015 at 02:22 PM
Look at coroutines, place a yield WaitForSeconds between the audio being played and the LoadLevel statement.
Your answer
 
             Follow this Question
Related Questions
Menu Animation 2 Answers
How would I add a scene delay timer to my script? 1 Answer
[Unity 4.6] UI Button problem null reference exception [Js] 0 Answers
Options UI over all scenes 1 Answer