- Home /
Rendering a camera in front of a gui element
I am looking to have a camera with a "Depth Only" clear flag render on top of a gui element. It seems that by default gui.depth and camera.depth are unrelated and that gui elements always render over camera viewports. Has anyone managed to do this?
Answer by Eric5h5 · Oct 14, 2010 at 07:11 PM
OnGUI code always renders on top of everything. If you need to layer GUI elements under 3D objects you can use GUIText/GUITexture.
Answer by roberto_sc · Feb 23, 2011 at 06:24 PM
from http://forum.unity3d.com/threads/38372-GameObjects-in-front-of-GUI
"Not directly. You could have a separate camera in your scene, place your gameobjects relative to the second camera, render the camera to a render texture, then use that render texture as the source of a GUI.DrawTexture, then you could achieve it."
One should mention that roberto_sc's solution (quoted from the posted link) requires Unity Pro (render to texture is a pro feature).
Answer by tyoc213 · May 09, 2014 at 06:17 PM
You need to create a "new camera" somewhere (outside of any possible camera you have, so that you don't get double render the same object in some place on the first camera) that "watch" something that you want to render over the GUI.
When your setup is correct, disable the camera.
On code after al you GUI render commands are over, do myCamera.Render()
Done.