Author Topic: localPosition to MousePosition  (Read 6746 times)

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
localPosition to MousePosition
« on: December 04, 2013, 03:07:11 PM »
I have this on a widgets OnPress

  1. var slotPosition = transform.localPosition.ToString ();
  2.                                 var mousePosition = Input.mousePosition.ToString ();
  3.                                 Debug.Log ("Mouse: " + mousePosition);
  4.                                 Debug.Log ("Slot: " + slotPosition);

The output is:
Quote
Mouse: (235.0, 636.0, 0.0)
Slot: (0.1, 0.7, 0.0)

I dont understand the difference between the vectors. How can i position the localPosition of the widget to where mouse is?

And even more, where can i read up on how Ngui/Unity is arranged so i better can understand?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: localPosition to MousePosition
« Reply #1 on: December 04, 2013, 03:10:05 PM »
Use Camera.ScreenToWorldPoint to transform coordinates from screen space that Input.mousePosition is in to world coordinates. Then use the widget's transform.InverseTransformPoint to convert it to local coordinates. To position the widget you will instead want to use transform.parent.InverseTransformPoint. And note that this isn't an NGUI question.

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: localPosition to MousePosition
« Reply #2 on: December 04, 2013, 05:00:42 PM »
Thank! I appreciate it.