Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: SatMangieri on October 16, 2014, 06:13:45 AM

Title: NGUI positions VS Unity Positions - SOLVED
Post by: SatMangieri 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.
Title: Re: Make Some Improvements please!
Post by: badawe 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.  
Title: Re: Make Some Improvements please!
Post by: SatMangieri 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)
Title: Re: NGUI positions VS Unity Positions - SOLVED
Post by: ArenMook on October 16, 2014, 07:03:03 AM
"Thank you" button should be beside the Quote one.