• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTrigger - playing sound once with delay 2 Answers

Does framerate affect Coroutines? 1 Answer

Getting a variable timed Interval with coroutine and yield? 0 Answers

Trying to move buttons via Coroutine and transform.Translate 0 Answers

Coroutine: delay transform rotation but start transform movement immediately 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges