Is there a way to render gui elements outside of the OnGUI function?
You can call methods / functions from OnGUI which can then render GUI elements; so a modular GUI is very possible.
However, an immediate mode system (which Unity GUI is) will probably never let you call its functions from “outside” the control flow of the GUI-hook function (OnGUI). That’s simple not the way an immediate mode GUI system is designed (took me a while to like this kind of GUI system - but once you’re starting to get the hang of it, it becomes very clear that this is totally superior for game UIs).
So, when you need a state change for the GUI, what you’d usually do is change the state of the MonoBehaviour which implements OnGUI and then simply use that changed state from your UI methods.
No! Never-ever! Bad!
By the way I recommend checking out the unite 07 presentation of the GUI system: http://unity3d.com/support/resources/unite-presentations/in-game-gui-made-easy
Agreed. Calling GUI methods from non-OnGUI-code is EVIL! :twisted: