Author Topic: positioning ngui elements in 3D world  (Read 7109 times)

alexv

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 1
  • Posts: 22
    • View Profile
positioning ngui elements in 3D world
« on: September 15, 2014, 09:10:55 AM »
Hi there,

I was wondering if there's an easy way to make NGUI elements be positioned in 3d world-space.
Just like a health-bar or a balloon-talk on top of a character.

without ngui, I'd normally create a unity sprite, and child it to my character's empty gameobject, which is positioned on top of his head.... so the sprite will float on top of character's head.

As I understand it, NGUI uses a UI Root 3D parent, which I shouldn't unparent it from, but that ui root scales the ui elements with a very low factor (0.00x).

...so, what's the NGUI way of "parenting" an UI element (that should be seen through a main 3d camera) to a moving character in world space?

thanks in advance


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: positioning ngui elements in 3D world
« Reply #1 on: September 16, 2014, 08:40:23 AM »
Have a look at transform.OverlayPosition (found in NGUIMath). You can use it to position a 2D UI element on top of a 3D object. You can also achieve the same thing just by using widget anchors and specifying a 3D object as the anchor's target.

If you have a 3D world and you want it to have NGUI elements instead, then just create a game object, add UIPanel to it, and you can put widgets underneath. It doesn't need the UIRoot. You will still want to scale it down though.

alexv

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: positioning ngui elements in 3D world
« Reply #2 on: September 29, 2014, 01:41:58 PM »
thanks aren, that helps a lot! I got it working!