Author Topic: Get and Set X,Y value of NGUI elements in Pixels just like height and width  (Read 1852 times)

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Hi there,

We can set height and width (size) of NGUI's widget. But how can we set and get x and y position of NGUI Widget in pixels?

Please Advise
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
One way is to use widget.SetScreenRect(x, y, width, height); -- exactly as you would with OnGUI. This function uses top-left corner as XY, just like OnGUI.

widget.SetRect(x, y, width, height) is another way -- it uses XY as bottom-left corner, which is how the coordinate origin everywhere except Windows.

You can also simply set the widget's transform.localPosition manually. It's in pixels.