- Home /
When to use OnGUI() ?
Hi,
I was wondering in what instances I should be using the OnGUI() function to do things. For example, I know I can display textures on the screen using the GUITexture component together with Texture2D's which hold the textures. However, I was wondering if anyone can provide some information on the when/why to use OnGUI().
I have read that OnGUI() updates many times every frame. So if this is the case and I'm not using it with my GUITextures, then how often are they updating? Are they still using the OnGUI() function in the background elsewhere?
Thanks
Answer by Eric5h5 · Oct 09, 2012 at 11:17 PM
GUITextures and OnGUI code are separate things. GUITextures are basically standard Unity GameObjects, though they use viewport space for coordinates. OnGUI is a function that only uses immediate mode code. ("Updates many times per frame" is an exaggeration though; most likely it is twice.) Use OnGUI when you have complex GUI needs that would be cumbersome or impossible to implement with GUITextures and GUIText.