Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: tnbao91original on June 15, 2014, 12:14:34 PM

Title: How to implement floating hud controls in NGUI ?
Post by: tnbao91original on June 15, 2014, 12:14:34 PM
Hi, i want to make a heath bar in 3D game look like this http://www.daikonforge.com/dfgui/examples/floating-hud-controls/ in Daikon UI. I'm newbie with Unity and NGUI so anyone know how to do that ?
Title: Re: How to implement floating hud controls in NGUI ?
Post by: ArenMook on June 16, 2014, 07:03:45 AM
Easiest way -- just anchor the UI element to the 3D object. You will generally want to organize your UI element like this:

Widget (anchored)
- Slider for HP
- Label for the name

Alternatively you'd write a script to convert from world to screen point, or just use the HUDText plugin if you have that.
Title: Re: How to implement floating hud controls in NGUI ?
Post by: tnbao91original on June 16, 2014, 10:27:45 AM
Thank you for support, i don't have HUDText plugin so may you show me an example how to convert from world to screen point :) It's very useful for me
Title: Re: How to implement floating hud controls in NGUI ?
Post by: ArenMook on June 17, 2014, 10:46:16 AM
// Take the 3D point and convert it to screen
Vector3 pos = Camera.main.WorldToScreenPoint(yourObject.transform.position);

// Now take this world point and make it relative to the widget you want to reposition
pos = yourWidget.transform.parent.transform.InverseTransformPoint(pos);

// Now position your widget
yourWidget.transform.localPosition = pos;