Hi,
I've been trying to get this to work unsuccessfully.
I have a sprite in my NGUI Scene that I want to match to my mouse/touch position. My NGUI Scene is an additively loaded scene that contains the GUI and a Camera. This is loaded by every Scene in my game when the level starts.
What I'm doing is taking the mouse/touch positon (which is in screen space) and using the GUI's camera to transform that position Screen->Viewport, then using the viewport position to set the position of the NGUI sprite.
Vector3 realPosition = HUDCamera.ScreenToViewportPoint(mouseScreenPosition);
realPosition.x = (realPosition.x - 0.5f);
realPosition.y = (realPosition.y - 0.5f);
transform.position = realPosition;
For some reason, this is not working properly, there is always a disconnect between the mouse/touch and the sprite's position.
Should I be doing something different? I feel I don't understand how NGUI's coordinates relate Unity's coordinates.
Thanks
- Ricardo