Author Topic: using WorldToScreenPoint to move a button to position  (Read 2982 times)

benjaben

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
using WorldToScreenPoint to move a button to position
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: using WorldToScreenPoint to move a button to position
« Reply #1 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);