Created
May 17, 2015 17:23
-
-
Save unitycoder/c4024061107c53bde3c9 to your computer and use it in GitHub Desktop.
Revisions
-
unitycoder revised this gist
May 17, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ using UnityEngine.EventSystems; using UnityEngine.UI; // http://forum.unity3d.com/threads/eventtrigger-move-issue.325103/#post-2114563 public class TrackMouseOverUI: MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { -
unitycoder created this gist
May 17, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.UI; public class TrackMouseOverUI: MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { // Called when the pointer enters our GUI component. // Start tracking the mouse public void OnPointerEnter( PointerEventData eventData ) { StartCoroutine( "TrackPointer" ); } // Called when the pointer exits our GUI component. // Stop tracking the mouse public void OnPointerExit( PointerEventData eventData ) { StopCoroutine( "TrackPointer" ); } IEnumerator TrackPointer() { var ray = GetComponentInParent<GraphicRaycaster>(); var input = FindObjectOfType<StandaloneInputModule>(); if( ray != null && input != null ) { while( Application.isPlaying ) { Vector2 localPos; // Mouse position RectTransformUtility.ScreenPointToLocalPointInRectangle( transform as RectTransform, Input.mousePosition, ray.eventCamera, out localPos ); // local pos is the mouse position. Debug.Log(localPos); yield return 0; } } else UnityEngine.Debug.LogWarning( "Could not find GraphicRaycaster and/or StandaloneInputModule" ); } }