Author Topic: How can I make a UILabel in a scene always render on top?  (Read 4030 times)

Meltdown

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 56
    • View Profile
How can I make a UILabel in a scene always render on top?
« on: March 10, 2014, 09:23:28 PM »
In our current project we are having a Windows Phone 8 specific issue where UILabel text that is supposed to be drawn in front of the enemy, is in some cases being drawn behind or in it.

See the attached image..

Is there any way to force the label to be drawn in front? And how can I change the shader for this UILabel?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can I make a UILabel in a scene always render on top?
« Reply #1 on: March 11, 2014, 05:56:17 PM »
If the label is a part of your 3D scene (drawn with the 3D camera), then it will be affected by depth. This is why the UI is typically drawn using a separate, orthographic camera.

If you want to use 3D UI elements and want them to always be on top, create a 3D UI instead of placing UI elements in your world (read: separate UI camera).

Meltdown

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 56
    • View Profile
Re: How can I make a UILabel in a scene always render on top?
« Reply #2 on: March 18, 2014, 06:58:23 PM »
For anybody else who wants to make sure the text is always rendered on top, you can modify the NGUI Text Shaders by adding ZTest Always to the shader.

So in the NGUI/Resources/Shaders folder, edit Unlit - Text.shader...

Under the first line that says ZWrite Off

add this line...

ZTest Always