Author Topic: Allow certain 3D objects to overlap certain UI elements  (Read 2400 times)

hazelsparrow

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 0
    • View Profile
Allow certain 3D objects to overlap certain UI elements
« on: December 29, 2014, 03:24:04 PM »
Hi,

I'm new to Unity so if the question I'm asking indicates that I misunderstand some fundamental concept in Unity and there is another approach to what I'm trying to do I would appreciate anyone sharing it.

So I have characters in my world and those characters have their names hovering above their heads. The names are gameobjects added under UI Root having a UILabel attached to them. UIFollowTarget's game camera is set to the main camera and UI camera is set to the NGUI's Camera (under UI Root).

Since the names are NGUI objects, they are drawn by the NGUI Camera which has a depth of 1 whereas my main game camera has a depth of 0. (I would imagine this is a pretty standard setup.) Now, my character names are always on top, although the characters themselves might be hidden behind home walls or other characters or other 3D objects, even terrain. I would like to apply the same occlusion culling to my labels just like it's applied to characters themselves. This will give it a more natural look.

What is the best way to do it?

I attached a screenshot to illustrate what I mean. The character in the front is the main player character and it doesn't have a name. The character in the back, partially hidden behind the hill, is an NPC with his name floating above him. (Actually more like at his feet, but it doesn't matter for now.) You can see that this label overlaps my main character and the terrain. What I would like to have in this case is just a "ter" visible to the right from the hill's edge, or maybe the entire label hidden altogether.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Allow certain 3D objects to overlap certain UI elements
« Reply #1 on: December 30, 2014, 02:21:31 PM »
The only way to do that is to make your labels a part of your main camera's world, not a part of your UI. Currently your UI elements are drawn after all of your world elements, so there is nothing to occlude. What you want to do is this:

1. Create a game object on the same layer as your game characters (presumably "Default").
2. Add a UIPanel to this object.
3. Underneath this object add widgets as usual. Ie: ALT+SHIFT+L to add a label. It will be huge by default, so you will want to shrink the UIPanel down to a reasonable size (such as 0.01, 0.01, 0.01).

Don't use UIFollowTarget in this case. You will make this game object a child of your 3D character and will want to use a script that will always make it face the camera.