void OnGUI () {
GUI.depth = 2;
if (Guib){
GUI.skin = GuiSkin;
GuiF();
}
}
void GuiF(){
GUI.Box(new Rect(0,0,50,50),"dsfg");
GUILayout.BeginArea(new Rect(0,0,Screen.width,Screen.height));
GUILayout.Box("I'm Name");
GUILayout.Box("I'm Health");
GUILayout.Box("I'm Stamina");
GUILayout.Box("I'm Nutrition");
GUILayout.Box("I'm fOOd");
GUILayout.Box("I'm Water");
GUILayout.Box("I'm Bladder S**T");
GUILayout.Box("I'm Bladder water");
GUILayout.Box("I'll get back to this later");
GUILayout.Box("tho I think that's all I need");
GUILayout.EndArea();
}
hat's quite simple. The reason for this error is always the same. You changed the content of your GUI between the Layout and Repaint event. OnGUI is called for many different events (See the EventType enum for the full list).
Before each event Unity calls an additional Layout event. In this event Unity collects the information how many elements you have at the moment and hoe they are nested. This information is needed by the Layouting system.
When the actual event is processed it's vital that OnGUI has the same content as it has when the Layout event was called. That's why you shouldn't place any logic that changes the state of your GUI inside OnGUI. If you want place it in OnGUI, wrap it in
if (Event.current.type == EventType.Repaint)
{
//
}
When you change the state **at the end** of OnGUI, so the elements aren't affected since they are already drawn.
Or use
if (Event.current.type == EventType.Layout)
{
//
}
when you place your code before the actual GUI elements.
Anyway in general it's better to put any logic in Update.
edit
On this question i've posted a quite detailed post how the GUI system works if you want to gain some more knowledge about Unity ;).