Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ricardo on November 01, 2012, 12:52:03 PM

Title: Sprite that follows mouse/touch position
Post by: ricardo on November 01, 2012, 12:52:03 PM
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.

  1. Vector3 realPosition = HUDCamera.ScreenToViewportPoint(mouseScreenPosition);
  2.                
  3. realPosition.x = (realPosition.x - 0.5f);
  4. realPosition.y = (realPosition.y - 0.5f);
  5.                
  6. transform.position = realPosition;
  7.  

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
Title: Re: Sprite that follows mouse/touch position
Post by: ArenMook on November 01, 2012, 01:03:42 PM
Have you looked at UICursor?
Title: Re: Sprite that follows mouse/touch position
Post by: ricardo on November 01, 2012, 05:37:30 PM
Have you looked at UICursor?

Where can I find it? I dont' see it in my NGUI folder.
Title: Re: Sprite that follows mouse/touch position
Post by: ArenMook on November 02, 2012, 02:37:34 AM
It's a part of the inventory example that comes with a full version of NGUI.