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 /
avatar image
1
Question by meena · Sep 24, 2011 at 09:11 PM · coroutineyieldloadlevel

coroutine or yeild for OnGUI?

Hi all,

I have a simple toolbar that I am using to load the different levels of my application; the problem I am having is that when I attach the application.loadlevel script to a specific level's main camera, the other scripts in that given level stop functioning - however, the other levels function perfectly.

After doing some research, I thought that maybe this had to do with the execution order of the OnGUI script vs. the other Update scripts...but I don't know. Here's my application.loadlevel script:

 var toolbarInt = 0;
 var toolbarStrings : String[]= ["ReLoad", "Level 1", "Level 2", "Level 3"];
 var mySkin : GUISkin;
 
 function OnGUI () {
 
     GUI.skin = mySkin;    
     toolbarInt = GUI.Toolbar (Rect (Screen.width - 300, Screen.height - 40, 290, 30), toolbarInt, toolbarStrings);
     
     if (toolbarStrings[toolbarInt] == "ReLoad") {
     Application.LoadLevel (0);
     }    
     if (toolbarStrings[toolbarInt] == "Level 1") {
     Application.LoadLevel (1);
     }    
     if (toolbarStrings[toolbarInt] == "Level 2") {
     Application.LoadLevel (2);
     }    
     if (toolbarStrings[toolbarInt] == "Level 3") {
     Application.LoadLevel (3);
     }                                                                    
 }

Do I need to make the GUI part a coroutine (ie, make it run after the update scripts are called)? If so, how do I do this?

Thanks in advance.

Comment
Add comment · Show 3
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 meena · Sep 25, 2011 at 01:24 AM 0
Share

Thank you! So just to be sure I get it right, when I create the new string: -Do I just have an empty return field, for the "Do Nothing" button? -How do I make it the default option? -What if I don't want another button on the toolbar though? Again, thank you so, so much for your help.

avatar image meena · Sep 28, 2011 at 01:40 PM 0
Share

This question was answered twice, but the correct answer disappeared when I was deleting my own misplaced answer (which should've been a comment). Sorry all.

Basically, the answer was that there needed to be another string called "Default" which allow time for the OnGUI scripts to be called before loading a level; otherwise Application.LoadLevel (0) is called multiple times. I don't think I did the original person answering the question justice here.

avatar image syclamoth · Sep 28, 2011 at 01:56 PM 0
Share

Sorry! Something weird happened there. Anyway, I've undeleted my answer (somehow).

1 Reply

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

Answer by syclamoth · Sep 28, 2011 at 01:55 PM

None of the above- the problem here is that your GUI script will be calling Application.LoadLevel(0) every single GUI step! You need to create another string in your toolbar, which says "Do Nothing" or "Choose Option" and just sits there and does nothing, and is also the default option. This way, the GUI will wait until you have made your choice before doing anything!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Yield WaitForSeconds doesn't work, give syntax error 1 Answer

Wait For Seconds to Load level C# 2 Answers

C# Wait for Coroutine 3 Answers

How to set timer for WWW helper? 1 Answer

Execution manner of co routine 2 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