Author Topic: NGUI positions VS Unity Positions - SOLVED  (Read 7729 times)

SatMangieri

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 9
    • View Profile
NGUI positions VS Unity Positions - SOLVED
« on: October 16, 2014, 06:13:45 AM »
How do i make the conversion of NGUI position to Unity position (And Vice Versa).
If i have a widget with a .localposition = (-10,200,0);
And i have a Game Object with .position = (-2.5,0.0);
I need to move the NGUI widget just above the unity Game Object. How do i do that?
Things to consider here:
UIRoot is Pixel Perfect. The Main Orthographic Camera has size of 5.

I need the reference to do it (But something you have tested in the same conditions).

PS: I've been looking for old posts but i cannot find a clear example about how to do this at least not with pixel perfect.
« Last Edit: October 16, 2014, 06:43:35 AM by SatMangieri »

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: Make Some Improvements please!
« Reply #1 on: October 16, 2014, 06:24:54 AM »
Hi dude, keep calm the support of NGUI is way better than much others softwares out there! And your question was replied a lot of times, was pretty easy found the answer, but here is what you want:


  1. //Get the position of the object that you want.
  2. Vector3 pos = mGameCamera.WorldToViewportPoint(target.position);
  3.  
  4. //Move the target GUI Element to the desired position
  5. transform.position = mUICamera.ViewportToWorldPoint(pos);
  6. pos = transform.localPosition;
  7. pos.x = Mathf.RoundToInt(pos.x);
  8. pos.y = Mathf.RoundToInt(pos.y);
  9. pos.z = 0f;
  10. transform.localPosition = pos;
  11.  

SatMangieri

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 9
    • View Profile
Re: Make Some Improvements please!
« Reply #2 on: October 16, 2014, 06:41:58 AM »
Ty so much Buddy.
Yeah i know is much better than many others support services  but sometimes the deadlines have a special pressure on your coding requirements.

Thanks a Lot @badawe

PS: how do i give you a "thank you"? (i mean the one that count on your community profile)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI positions VS Unity Positions - SOLVED
« Reply #3 on: October 16, 2014, 07:03:03 AM »
"Thank you" button should be beside the Quote one.