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

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.

There are few options here…

  1. 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).
  2. Use 3D text instead of GUI.Label, then simply treat it as a world object, and place other objects in front or behind it.
  3. 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…

You might find this helpful …

Here