Delay Application.LoadLevel
Hello! I was trying to make main menu for my game. I wanted to have sound when clicking "start game" button, but when I use yield WaitForSeconds (3); my sound is playing after those 3 seconds, and it plays for only about half a second and then the level loads. I want this sound playing immediately after pressing the button. I was wondering if anybody can help me. Here's my main menu script:
var isQuit=false;
var hoverSound : AudioClip;
var clickSound : AudioClip;
var levelNumber : int;
function OnMouseEnter(){
GetComponent.().material.color=Color.red;
GetComponent.().PlayOneShot(hoverSound);
}
function OnMouseExit(){
GetComponent.().material.color=Color.white;
}
function OnMouseUp(){
if (isQuit==true) {
Application.Quit();
}
else{
yield WaitForSeconds (3)
Application.LoadLevel(levelNumber);
GetComponent.().PlayOneShot(clickSound);
}
}
function Update(){
if (Input.GetKey(KeyCode.Escape)) {
Application.Quit();
}
}
Sorry for my bad english :D
Wouldn't you just want to move your call to PlayOneShot before the yield?
oh, I didnt think about it. I'm so stupid ;( Thank you so much :)
Answer by getyour411 · Sep 01, 2015 at 12:31 AM
Personally I would not go the route of artificially pausing the game so a sound can play. Instead, play the sound on an object that has DontDestroyOnLoad so that it transitions into the next scene.
Your answer

Follow this Question
Related Questions
How to delay a function? 3 Answers
Linux Standalone player slow startup after version 5.2 0 Answers
script delay ("on mouseclick") 0 Answers
Delay while rotating a camera (doesn't happen in the editor) 0 Answers