Enable and Disable OnGUI on iPhone

It has been fairly well stated here in the forums that OnGUI will kill your framerate. But GUIText and Texture are a serious PITA to layout. Anyone have a good solution to turn OnGUI on and off? I was trying to turn the script or game object on/off but its not really working and I just read that disabling a script only disables Start(), Awake(), Update and FixedUpdate(). Weird.

I am currently using GUIText/Textures for the in game HUD but everything else like menus, pause, etc. would be so much easier to do in OnGUI.

Any help would be greatly appreciated : )

Add the component when you need it, when you don’t need it anymore, trash it with Destroy or DestroyImmediate

Easier just to enable/disable the script, or activate/deactivate the object it’s on.

–Eric

dreamora - Thanks that works perfectly… sometimes the simplest stuff is the most elusive : )

Eric5h5 - Is it possible that you may have just been wrong for the first time ever on this forum!? ; ) Everything you say ALWAYS works, but unless something else was wrong in my testing and what I read…

“disabling a script only disables Start(), Awake(), Update and FixedUpdate().” it does not mention OnGUI and I gathered that OnGUI runs a separate routine since people have found that it actually is invoked before Awake(). Strange right.

No. :wink: Probably that part of the docs was written before OnGUI existed, and never updated. Because this:

function OnGUI () {
	if (GUILayout.Button("Go away!")) {
		this.enabled = false;
	}
}

…works.

–Eric