Support => NGUI 3 Support => Topic started by: Lautaro on December 04, 2013, 03:07:11 PM
Title: localPosition to MousePosition
Post by: Lautaro on December 04, 2013, 03:07:11 PM
I have this on a widgets OnPress
var slotPosition = transform.localPosition.ToString();
var mousePosition = Input.mousePosition.ToString();
Debug.Log("Mouse: "+ mousePosition);
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?
Title: Re: localPosition to MousePosition
Post by: ArenMook on December 04, 2013, 03:10:05 PM
Use Camera.ScreenToWorldPoint (http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html) 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.
Title: Re: localPosition to MousePosition
Post by: Lautaro on December 04, 2013, 05:00:42 PM