Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started 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 ?
-
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.
-
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
-
// 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;