Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Dec 15, 2015 at 04:02 AM by thelenf for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by thelenf · Dec 15, 2015 at 02:48 AM · c#not workingwaitforsecondsienumeratorstartcoroutine

IENumerator does not work

Hi, I'm still new with c# and still learning, thats why I'm stuck around here.

What I'm trying todo is.. making the gameobject and entire script to pause and then continue after 2 seconds.

Many had put up a discussion about this, but I can't seem to get the code right.

I searched alot on the internet, and decided to use yield waitforseconds and then call using startcoroutine into my void function. But, I really don't know what I did wrong. There is no error in code, and none effect on my program too...

This is the part of the codes :

 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 == 2){
                 Application.LoadLevel ("main2"); 
             }else{
                 Application.LoadLevel ("main");
             }
         } else {
             Debug.Log ("Wrong");
             AudioIsPlaying.isPlayingWrongCorrect = 2;
             if(MyScore.live == 1){
                 MyScore.score = 0;
                 MyScore.stage = 1;
                 Application.LoadLevel ("GameOver"); //go to gameOver Scene
             }else{
                 --MyScore.live;
                 txtLives.text = MyScore.live.ToString ();
             
                 StartCoroutine(WaitPopup(5)); // I can't get this work
 
                 Application.LoadLevel ("main");
             }
         }
     }
 
     IEnumerator WaitPopup (float duration){
         Debug.Log ("test1"); 
         popupwrong.SetActive (true); // the game object I wanted to show and then pause
         Debug.Log ("test2");
         yield return new WaitForSeconds (duration);
         Debug.Log ("test3");
         popupwrong.SetActive (false);
     }

Thank you

Comment
Add comment · Show 2
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
avatar image gjf · Dec 14, 2015 at 07:49 PM 1
Share

StartCoroutine() will return immediately after creating the coroutine... you should do the LoadLevel()in your WaitPopup() function after your waiting...

avatar image thelenf gjf · Dec 15, 2015 at 04:02 AM 0
Share

Thank you very much! That solved the problem. I cant believe how simple is the mistake I made. :3 Really appreciate it.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Trying to add a delay to an Instantiate in a For Loop 0 Answers

nothing called after WaitForSeconds 1 Answer

How to skip WaitForSeconds? 1 Answer

StartCoroutine & WaitForSeconds Error 1 Answer

How to add multiple yield return new wait for seconds inside an IEnumerator? 1 Answer


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