Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: benjaben on January 23, 2014, 04:53:45 AM

Title: using WorldToScreenPoint to move a button to position
Post by: benjaben on January 23, 2014, 04:53:45 AM
I have an object in world space at (-95, 0, 16) and I'd like to move a button on screen to be above that object during runtime. However when I do this the button is quite a bit off. It seems like WorldToScreen point is return the pixels from the edge of the screen (which I understand). I just don't quite get how to move the NGUI button over the exact position of the object.
Title: Re: using WorldToScreenPoint to move a button to position
Post by: ArenMook on January 23, 2014, 05:19:36 AM
You can use the new anchoring system to do this quite easily by simply setting the anchor to be your target object.

Otherwise, convert from screen to widget's parent's local coordinates.

  1. widget.transform.localPosition = widget.transform.parent.InverseTransformPoint(worldPos);