- Home /
Hide GUI Label behind an object?
Hello everyone. I have a question on how to hide a GUI Label when it's behind a object. My problem is that I'm able to see the Label even if it's behind a object! Here is my GUI Label:
private var localName : String;
private var namePlatePos : Vector3;
var namePlate : GUIStyle;
GUI.Label(Rect((namePlatePos.x-50), (Screen.height - namePlatePos.y+10), 100, 50), localName, namePlate);
Please can someone help me? Thanks, any help is appriciated
Answer by The Kracken · Dec 07, 2013 at 01:17 AM
If you are trying to hide it behind a 3D object you have to do some GUI magic. The GUI is drawn last and above everything else in the scene. If you added some pictures of what you are trying to achieve we could help you more.
Answer by Tomer-Barkan · Dec 07, 2013 at 07:12 AM
There are few options here...
Use GUIText object instead of GUI.Label, then set the camera that draws the object to draw after the camera that draws the GUI (the object's camera needs higher depth value, and the GUI Layer component needs to be disabled).
Use 3D text instead of GUI.Label, then simply treat it as a world object, and place other objects in front or behind it.
Determine which labels should be behind the object, and simply don't display them.
Unfortunately, with current Unity scripted GUI, there is no option to display it behind game objects. It is always rendered last, after all cameras have rendered. Unity announced a new GUI in one of the coming 4.X versions, it might be better then...
Your answer
![](https://koobas.hobune.stream/wayback/20220613123612im_/https://answers.unity.com/themes/thub/images/avi.jpg)