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?
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."
- 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.
OnGUI code always renders on top of everything. If you need to layer GUI elements under 3D objects you can use GUIText/GUITexture.