Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by laurienash · Nov 06, 2014 at 08:13 PM · coroutine

application loadlevel c# calling coroutine not working?

Hi - I'm struggling to get the Application.LoadLevel working using C# (it seems a lot more confusing than JavaScript)

I don't know whether to post my whole code on it's quite long - but essentially when the screen turns black and the gameOver is true, I want a short delay before a different level loads.

But I'm getting two errors on calling the coroutine - 'Identifier expected' and 'Unexpected symbol `0' in class, struct, or interface member declaration'.

 void checkGameOver()
     {
         if(camA3.gameObject.activeInHierarchy == true)
         {
             if(A3B3 == true && A3A4 == true)
             {
                 if(A3W.GetComponent<BoxCollider>().isTrigger == false && A3B2W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camA4.gameObject.activeInHierarchy == true)
         {
             if(A4B4 == true && A3A4 == true)
             {
                 if(A4W.GetComponent<BoxCollider>().isTrigger == false && A4B5W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camB2.gameObject.activeInHierarchy == true)
         {
             if(B2B3 == true && B2C2 == true)
             {
                 if(B2C1W.GetComponent<BoxCollider>().isTrigger == false && B2A3W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camB3.gameObject.activeInHierarchy == true)
         {
             if(B3B4 == true && B3C3 == true && A3B3 == true && B2B3 == true)
             {
                 gameOver = true;
             }
         }
         else if(camB4.gameObject.activeInHierarchy == true)
         {
             if(B4B5 == true && B4C4 == true && A4B4 == true && B3B4 == true)
             {
                 gameOver = true;
             }
         }
         else if(camB5.gameObject.activeInHierarchy == true)
         {
             if(B5C5 == true && B4B5 == true)
             {
                 if(B5A4W.GetComponent<BoxCollider>().isTrigger == false && B5C6W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camC1.gameObject.activeInHierarchy == true)
         {
             if(C1C2 == true && C1D1 == true)
             {
                 if(C1B2W.GetComponent<BoxCollider>().isTrigger == false && C1W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camC2.gameObject.activeInHierarchy == true)
         {
             if(B2C2 == true && C2D2 == true && C1C2 == true && C2C3 == true)
             {
                 gameOver = true;
             }
         }
         else if(camC3.gameObject.activeInHierarchy == true)
         {
             if(B3C3 == true && C3D3 == true && C2C3 == true && C3C4 == true)
             {
                 gameOver = true;
             }
         }
         else if(camC4.gameObject.activeInHierarchy == true)
         {
             if(B4C4 == true && C4D4 == true && C3C4 == true && C4C5 == true)
             {
                 gameOver = true;
             }
         }
         else if(camC5.gameObject.activeInHierarchy == true)
         {
             if(B5C5 == true && C5D5 == true && C4C5 == true && C5C6 == true)
             {
                 gameOver = true;
             }
         }
         else if(camC6.gameObject.activeInHierarchy == true)
         {
             if(C6D6 == true && C5C6 == true)
             {
                 if(C6W.GetComponent<BoxCollider>().isTrigger == false && C6B5W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camD1.gameObject.activeInHierarchy == true)
         {
             if(C1D1 == true && D1D2 == true)
             {
                 if(D1W.GetComponent<BoxCollider>().isTrigger == false && D1E2W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camD2.gameObject.activeInHierarchy == true)
         {
             if(C2D2 == true && D2E2 == true && D1D2 == true && D2D3 == true)
             {
                 gameOver = true;
             }
         }
         else if(camD3.gameObject.activeInHierarchy == true)
         {
             if(C3D3 == true && D3E3 == true && D2D3 == true && D3D4 == true)
             {
                 gameOver = true;
             }
         }
         else if(camD4.gameObject.activeInHierarchy == true)
         {
             if(C4D4 == true && D4E4 == true && D3D4 == true && D4D5 == true)
             {
                 gameOver = true;
             }
         }
         else if(camD5.gameObject.activeInHierarchy == true)
         {
             if(C5D5 == true && D5E5 == true && D4D5 == true && D5D6 == true)
             {
                 gameOver = true;
             }
         }
         else if(camD6.gameObject.activeInHierarchy == true)
         {
             if(C6D6 == true && D5D6 == true)
             {
                 if(D6W.GetComponent<BoxCollider>().isTrigger == false && D6E5W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camE2.gameObject.activeInHierarchy == true)
         {
             if(D2E2 == true && E2E3 == true)
             {
                 if(E2D1W.GetComponent<BoxCollider>().isTrigger == false && E2F3W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camE3.gameObject.activeInHierarchy == true)
         {
             if(D3E3 == true && E3F3 == true && E2E3 == true && E3E4 == true)
             {
                 gameOver = true;
             }
         }
         else if(camE4.gameObject.activeInHierarchy == true)
         {
             if(D4E4 == true && E4F4 == true && E3E4 == true && E4E5 == true)
             {
                 gameOver = true;
             }
         }
         else if(camE5.gameObject.activeInHierarchy == true)
         {
             if(D5E5 == true && E4E5 == true)
             {
                 if(E5D6W.GetComponent<BoxCollider>().isTrigger == false && E5F4W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camF3.gameObject.activeInHierarchy == true)
         {
             if(E3F3 == true && F3F4 == true)
             {
                 if(F3W.GetComponent<BoxCollider>().isTrigger == false && F3E2W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }
         }
         else if(camF4.gameObject.activeInHierarchy == true)
         {
             if(E4F4 == true && F3F4 == true)
             {
                 if(F4W.GetComponent<BoxCollider>().isTrigger == false && F4E5W.GetComponent<BoxCollider>().isTrigger == false)
                     gameOver = true;
             }    
 
     }
 
         if(gameOver == true) print("You ha

ve been trapped! Game Over"); }

         private bool setTimer = false;
     void OnGUI()
     {
         if (gameOver == true) 
         {
 
         
 
             if(setTimer == false)
             {
                 timer = fadeTime;
                 setTimer = true;
             }
             color.a = 1 - (timer / fadeTime);
         }
         else color.a = 0;
 
         GUI.color = color;
         GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), blackScreen);
 
 
 
     }
 
 
     IEnumerator MyLoadLevel(float delay, int level)
     {
         if (gameOver == true)
         {
         yield return new WaitForSeconds(delay);
         Application.LoadLevel(level);
     }
     }
     
     StartCoroutine(MyLoadLevel(15.0f,0));
 }



Sorry, this question seems to come up a lot on the forums - I just haven't worked out what bit I'm doing wrong.

All the best, Laurien

Comment
Add comment · Show 1
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 laurienash · Nov 07, 2014 at 12:27 AM 0
Share

Thanks - that was silly :/

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Uldeim · Nov 06, 2014 at 08:42 PM

It's a little bit hard to tell from your snippet, but it looks like your StartCoroutine is outside all your methods?

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Increment variable over time 4 Answers

Blinking & resource consumption 1 Answer

StartCoroutine gets the arglist type wrong 1 Answer

Invoke isn't working for a function with yield? 2 Answers

Yielding in a loop only as needed? 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