I want to make game’s background image as GUITextrue object, but
How to make GUITexture be behind of other normal 3d gameObject like sphere or planes?
Currently, GUITexture covers all other objects.
Thanks.
I want to make game’s background image as GUITextrue object, but
How to make GUITexture be behind of other normal 3d gameObject like sphere or planes?
Currently, GUITexture covers all other objects.
Thanks.
First off you’ll want to add a new layer in the inspector, and set the GUITexture’s layer to this new layer. Now select your Main Camera, click on ‘Culling Mask’ and uncheck the layer you just made, this will stop the main camera rendering objects (GUITextures) on this layer. Now go and create a second Camera and set its ‘Clear Flags’ to ‘Depth Only’ and its ‘Culling Mask’ to only render the layer you set up earlier for the GUITextures, then finally change this Camera’s ‘Depth’ to -1. This should put the GUITextures behind the 3D shapes.
oh it works. Thank you.
Main camera and second camera all needs to be set as ‘Depth Only’
Does this work for drawing a GUI.Box too? Because I can’t make it work, I only see the GUI elements but not my 3D object.
I’ve set my 3D object to another layer, set main camera’s culling to everything except this new layer with 3D object and set depth to 1. Then I created another camera, set clear flags to Depth only, culling mask only to the new layer with my 3D object and depth to -1.
Please help!
Anything drawn in OnGUI will be rendered in front of everything else (3D or otherwise), so there isn’t currently a way to have 3D objects render in front of OnGUI elements such as GUI.Box.
Alright, thanks for reply.
“how can i give layer to gui elements that i created in gui function”
You can use GUI.depth, but it will work only if each “layer” is being rendered from different script.
If in the same script (same OnGUI() method), the layering is determined by the order your components are rendered (back to front).
Also note that there is the “processing order” bug, which makes overlapping controls handling input (mouse, keys) unclickable.
Create a canvas, and in the Inspector, set its Render Mode to Screen Space - Camera. And make your main Camera the Render Camera. Add something to the canvas. Maybe buttons. You’ll see that you can now move your GUI elements back or in front of the rest of the game objects as you like. You can also change UI Scale Mode to Scale with screen size if you want that.