Question by
thelenf · Dec 15, 2015 at 07:17 AM ·
c#coroutinesoundstartcoroutine
The order of the sound played
Hi, I am trying to make sound only play when the popup comes up (the popup saying that you answered wrong and a buzzing wrong sound)
I think I put it before the popup. But, still the sound plays only after the popup gone away.
Can anyone show me What I did wrong here ?
Heres the code :
public void CheckAnswer()
{
string userAnswer;
userAnswer = inputField.text.ToUpper ();
if (userAnswer == answer) {
Debug.Log ("Correct");
AudioIsPlaying.isPlayingWrongCorrect = 1;
++MyScore.score;
++MyScore.stage;
if(MyScore.stage == 6){
Application.LoadLevel ("main2"); //Harus ke gameOver Scene
}else{
Application.LoadLevel ("main");
}
} else {
Debug.Log ("Wrong");
AudioIsPlaying.isPlayingWrongCorrect = 2; //this is the sound, it is playing after the Startcoroutine
if(MyScore.live == 1){
MyScore.score = 0;
MyScore.stage = 1;
Application.LoadLevel ("GameOver");
} else {
txtLives.text = MyScore.live.ToString ();
StartCoroutine(WaitPopup(1)); //sound plays after this
}
}
}
IEnumerator WaitPopup (float duration){
while (true) {
Debug.Log ("tes1?");
popupwrong.SetActive (true); // iwant the sound play together with this set true, even when I put the audio before this line. The result still the same
objTimer.SetActive(false);
Debug.Log ("tes2");
yield return new WaitForSeconds (duration);
Debug.Log ("tes3");
MyScore.live = MyScore.live - 1;
popupwrong.SetActive (false);
Application.LoadLevel ("main"); //sound plays at this point???
}
}
your help would be very appreciated. Thanks before
Comment
Your answer
Follow this Question
Related Questions
OnTrigger - playing sound once with delay 2 Answers
Nothing after coroutine gets executed 1 Answer
Why my function does not work inside a corroutine used to load my scene. 0 Answers
Weird problem with simple boolean and "if" statement [C#] 0 Answers
Adding a CharacterController makes my player move around the map involuntarily 0 Answers