Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: galuodo on September 06, 2013, 05:16:36 AM

Title: Why positions seems so funny when used UIAnchor
Post by: galuodo on September 06, 2013, 05:16:36 AM
When I set the position of a game object, it works well at first. However after I used UIAnchor so that the game can be fit other resolution, the positions have a large deviation after the resolution changed.
  1.         void Update () {
  2.                 ul.transform.position = sp.transform.position+ new Vector3(5,5,0);
  3.         }
  4.  
Title: Re: Why positions seems so funny when used UIAnchor
Post by: Nicki on September 06, 2013, 07:41:54 AM
Remember to set localPosition for UI stuff. Position is the global position which may vary and make no sense.
Title: Re: Why positions seems so funny when used UIAnchor
Post by: galuodo on September 08, 2013, 08:57:01 PM
Thanks for your reply.
but i need world position to set underline or detect the location of mouse cursor and something else with out colliders, what should I do next?
Title: Re: Why positions seems so funny when used UIAnchor
Post by: Nicki on September 11, 2013, 05:56:13 PM
Well then you have to convert between local space and global space and maybe even screen space to be able to match everything. Setting some position + Vector3(5,0,0) can mean quite a difference when set in global space. Remember that NGUI operates in a very small global area (2 / UIRoot.activeHeight) so you should calculate how much you want to move in localSpace and convert to global.

I think there's a bunch of helper methods in NGUITools and NGUIMath that can help you as well.