I have 2 layers: GUI Layer, and 3D Layer. Each layer has a camera.
GUI Layer Camera settings:
- Clear Flags: Depth only
- Culling Mask: GUI Layer
- Depth: -1
- Component: a C# script with
OnGUI()
logic - GUILayer, Flare Layer & Audio Listener: On
3D Layer Camera settings:
- Clear Flags: Depth only
- Culling Mask: Everything but GUI Layer
- Depth: 0
- GUILayer, Flare Layer & Audio Listener: Off
My goal is to show the GUI elements behind 3D elements. The settings are okay, if the C# script is removed / disabled and GUITexture
components used instead. However, by using GUITexture
component, it is hard to control the size & logic via script.
Therefore, I have some images drawn by GUI.DrawTexture()
in scripts assigned to camera. For example:
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height),
backgroundTexture, ScaleMode.StretchToFill);
Although the script is attached to GUI Layer as Component, it does not draw behind the 3D objects; instead it is drawn in front of 3D objects.
My question is, how to assign GUI.DrawTexture()
to draw on specific layer / how to make the images drawn behind the 3D object?
Update Tried GUI.Depth = -99;
in OnGUI()
doesn't change the situation.