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.

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!