Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: laurentl on June 10, 2013, 01:53:28 PM

Title: Best way to anchor a widget to an object in the scene?
Post by: laurentl on June 10, 2013, 01:53:28 PM
I see that anchor only attach to camera, panels and widgets. Is there a script to attach to a 3D object so that the health bar follows the object?
Title: Re: Best way to anchor a widget to an object in the scene?
Post by: ArenMook on June 10, 2013, 02:42:02 PM
No, that's what UIFollowTarget does from the HUDText add-on. Also it's just 3 lines of code anyway.
Title: Re: Best way to anchor a widget to an object in the scene?
Post by: laurentl on June 10, 2013, 02:47:16 PM
I'm actually using it for context menu :)

I tried this but the UI gets sent really far.

  1.         void LateUpdate()
  2.         {
  3.                 transform.position = cam.WorldToScreenPoint (target.position);
  4.         }
Title: Re: Best way to anchor a widget to an object in the scene?
Post by: ArenMook on June 10, 2013, 11:23:19 PM
That's because WorldToScreenPoint gives you screen space coordinates, and then you just go and assign them to transform.position which is in world space coordinates.