Support => NGUI 3 Support => Topic started by: wilmerlin on January 22, 2013, 02:48:51 AM
Title: yield hangs from OnClick()
Post by: wilmerlin on January 22, 2013, 02:48:51 AM
I was trying to setup a script on a UIButton to load a level. It worked fine until I decided that I needed to pause the load of the new level with a yield. The CoRoutine gets called but it does not yield and instead just hangs.
It works fine if I remove the yield WaitForSeconds(delay) or set the delay to 0. Can I not call a Coroutine from OnClick()?
var levelToLoad:int=0;
var delay:float=1;
function OnClick(){
yield LoadLevelWithDelay();
}
function LoadLevelWithDelay(){
yield WaitForSeconds(delay);
Application.LoadLevel(levelToLoad);
}
Title: Re: yield hangs from OnClick()
Post by: ArenMook on January 22, 2013, 10:16:34 AM
NGUI has a script for this: LoadLevelOnClick.
Title: Re: yield hangs from OnClick()
Post by: wilmerlin on January 22, 2013, 10:58:13 AM
It does, but can I insert a yield WaitForSeconds() in there before the Application.LoadLevel? Or does it not work because of OnClick()?
My own function works until I attempt the yield. I can work around this by marking a time to load and loading the level in Update() but I thought this might have been the cleaner way to do it.
Title: Re: yield hangs from OnClick()
Post by: wilmerlin on January 22, 2013, 11:17:16 AM
Nevermind. I am a friggin' idiot. Have the time scale set to 0 because the game is paused. Doh.
Title: Re: yield hangs from OnClick()
Post by: gregba on March 12, 2013, 11:27:50 AM
I have just spent 2 days banging my head against the coding wall with exactly the same problem, glad I found your post and suddenly realized I was doing exactly the same as you! :o