Hi, would like to check is OnGUI() is always on top of any game object? Is it possible to place ONGUI() behind the game object? As i would like to create a border for my camera. I am thinking of using GUI.rect which i can draw a big rectangle for my camera. However, i realise my GUI.rect, will always place on top of my game object. Is there any others way that i am able to place it behind the game object?
I don’t think that is possible, however try to think about it the other way around:
The border should be part of the camera’s GUI, and therefore sitting above all game objects - use GUIContent() to add a 2D texture (ie your boarder) to the GUI.
The GUI layer is always rendered last and thus ontop of everything else. The only way of bringing a 3D object to the GUI is using render to texture and then drawing that texture on the GUI.
You can use GUITexture instead of OnGUI, and use more than one camera to layer the results, so the object is in front of the camera that’s rendering the GUITexture.
but arent they already deprecated? its also quite tedious to have mixed GUI system in the game, but I also havent figured out how to do it with RenderTexture… its easy to put an image to a Texture2D and draw it in GUI.Label or GUI.Box, but how do you put an image to a RenderTexture? because as far as I know RenderTexture get the input from camera view,…
or is it better to use a plane mesh to place GUIs?
I don’t think so; they’re recommended for iPhone use because they’re faster than using OnGUI, and removing them would break an awful lot of Unity content. It would take fewer resources and be faster and easier just to use two cameras and a GUITexture in this case, not to mention working with Indie as well as Pro, instead of messing around with rendertextures.
As of the 2.0 launch we definitely began, and continue to recommend UnityGUI for all your GUI needs, but that doesn’t mean we’ve yet pulled support for those from the product. Not only do need to support existing content, but until we have feature parity between the systems GUIText and GUITextures will remain in a supported state, they just won’t get any feature set advancement. Instead of developing GUIText and GUITextures, we’ll put that effort into UnityGUI (to bring parity and move beyond).
I think I’m doing something similar. I’m calling camera.Render() at the end of an OnGUI function to draw a single game object (on its own layer) over the top of the gui.
To anyone else, is my game taking a performance hit using this method? I’m preventing Unity from rendering this special camera and instead doing it manually so it should be the same number of draw calls?