Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: matt1 on November 29, 2014, 09:50:44 AM

Title: Make an object always follow your mouse
Post by: matt1 on November 29, 2014, 09:50:44 AM
Hi,


I am trying to make a GUI object always follow my mouse, I've tried to alter the DraggableObject script to always be true but so far havn't prevailed, is there an easier way to do it?

Many thanks

Matt
Title: Re: Make an object always follow your mouse
Post by: matt1 on November 29, 2014, 10:41:31 AM
I managed to achieve this by doing:

  1. public class DragGUI : MonoBehaviour {
  2.  
  3.         public GameObject DraggableSprite;
  4.         public Camera NGUICam;
  5.  
  6.         public Vector3 MoveUI(Vector3 Pos, Transform localSpace, Camera cameraNGUI) {
  7.                 Pos.x = Mathf.Clamp01 (Pos.x / Screen.width);
  8.                 Pos.y = Mathf.Clamp01 (Pos.y / Screen.height);
  9.  
  10.                 Vector3 WorldPos = cameraNGUI.ViewportToWorldPoint (Pos);
  11.  
  12.                 return localSpace.InverseTransformPoint (WorldPos);
  13.         }
  14.  
  15.  
  16.         void Update() {
  17.                 DraggableSprite.transform.localPosition = MoveUI( Input.mousePosition, DraggableSprite.transform.parent, NGUICam);
  18.         }
  19. }
Title: Re: Make an object always follow your mouse
Post by: matt1 on November 29, 2014, 12:26:29 PM
A problem i've ran into, that I can't figure a way around is:

If I have MouseButton(0) or (1) held down then void OnHover(bool IsOver) will not work, how can I work around this?

Thanks
Title: Re: Make an object always follow your mouse
Post by: ArenMook on November 30, 2014, 05:50:04 AM
When the mouse button is held down, you get OnDragOver/OnDragOut instead of OnHover.