• 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
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

People who like this

0 Show 0
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

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

40 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

Related Questions

OnTrigger - playing sound once with delay 2 Answers

Display multiple Text in a row for a certain time 1 Answer

Destroy() not removing the object all the time (Coroutine used) 0 Answers

C# Pause Menu Buttons not working in only 1 scene 1 Answer

StartCoroutine in a static member 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges