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
1
Question by LSnake2001 · Nov 06, 2011 at 05:43 PM · coroutineyieldwaitforseconds

Another yield not working problem

I've checked a lot of the questions about yields and tried a lot of different methods but can't get my code to work.

Here is my code:

private var sceneIndex : int; private var sceneName : String; private var sysFades : GameObject; sysFades = GameObject.Find("-main");

private var confirmSwitch : boolean = false;

private var confirmWin : Rect = Rect ((Screen.width/2)-65, (Screen.height/2)-30, 200, 60);

function OnGUI(){ if(confirmSwitch)confirmWin = GUI.Window (0, confirmWin, confirmSwitchFunction, "Switch to " + sceneName); }

function confirmSwitchFunction (windowID : int) { if (GUI.Button (Rect (10, 20, 50, 30), "Yes")) { switchScene(); } if (GUI.Button (Rect (70, 20, 50, 30), "No")) { confirmSwitch = false; } }

function webButtons(web_sceneIndex : int){ confirmSwitch = true; Debug.Log(sceneIndex); sceneIndex = web_sceneIndex;

 if(sceneIndex == 0)sceneName = "Scene 0";
 if(sceneIndex == 1)sceneName = "Scene 1";
 if(sceneIndex == 2)sceneName = "Scene 2";
 if(sceneIndex == 3)sceneName = "Scene 3";

}

function switchScene(){ Debug.Log("Fading Scene"); sysFades.SendMessage("sceneFadeOut"); confirmSwitch = false; yield WaitForSeconds (1); Debug.Log("Loading New Scene"); Application.LoadLevel (sceneIndex); }

I've tried starting switchScene as a coroutine and tried breaking down the code in switchScene into two functions either side of the yield. Basically, the code just stops running at the yield and the new scene never gets loaded. If I start the yield within the "Yes" button code the buttons stop appearing.


EDIT I've tried commenting out the SendMessage command as suggested and it still didn't work. Further to that I've unchecked all other scripts running in the scene and removed all scripts from all components.

I've also started a new scene in the same project with just a camera and an empty GameObject with code taken from the ref docs and other internet sources. This doesn't work. But I've switched to a different project and tried the code in that and it works fine. So, what could it be about my project that is causing it to not work?

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

2 Replies

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

Answer by LSnake2001 · Nov 15, 2011 at 08:18 PM

Thanks for the reply, aldonaletto. I'm not sure why this didn't work but I've fixed it by starting a new project and importing my previous project into that. I'm guessing the previous project was corrupt or something.

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
avatar image
1

Answer by aldonaletto · Nov 06, 2011 at 06:37 PM

This code doesn't seem to be causing this issue. I suspect that the routine sceneFadeOut may be doing something wrong and screwing things up - it has one second to do that... Try to comment out the SendMessage instruction to test this, or edit your question and post the other script.

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

Getting an error when trying to yield 2 Answers

yield works, but yield WaitForSeconds does not? 1 Answer

Playing footsteps with interval 1 Answer

Load Level when dead for 1 second 2 Answers

Yield WaitForSeconds doesn't work, give syntax error 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