Author Topic: UIGrid items' position errors  (Read 2932 times)

netlander

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 11
    • View Profile
UIGrid items' position errors
« on: June 16, 2014, 05:48:36 AM »
Hi,

I have a UIGrid filled with sprites arranged in a rectangle and I am trying to position other game objects on top of some of those sprites at runtime.

The issue is when I try to get the positions of the sprites inside the grid it seems that the transforms of those sprites are returning the wrong positions, I have a simple script attached to the grid's sprites and when I access the transform's position of those sprites from within this script I get a small number like (0.5, 0.7, 0) but the position I need to get is the one that's shown in the Inspector, i.e. something in the form of (200, 200, 0).

Any ideas why is this happening? (needless to say I'm a noob with NGUI).  :D

Cheers
Paul

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid items' position errors
« Reply #1 on: June 16, 2014, 08:47:47 AM »
Check transform.localPosition instead of transform.position. There is a world of difference between World position and Local position. You need to be aware of how transforms work.

netlander

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 11
    • View Profile
Re: UIGrid items' position errors
« Reply #2 on: June 16, 2014, 09:04:14 AM »
Yes I came over to update this thread with the answer. Indeed it's the transform.localPosition.

Thanks