Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- public class MouseEnterScript : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
- {
- public void OnPointerEnter(PointerEventData eventData)
- {
- Debug.Log("Over Name: " + eventData.pointerCurrentRaycast.gameObject.name);
- Debug.Log("Over Tag: " + eventData.pointerCurrentRaycast.gameObject.tag);
- Debug.Log("Over GameObject: " + eventData.pointerCurrentRaycast.gameObject);
- mouseOver = true;
- gameObjectDetected = eventData.pointerCurrentRaycast.gameObject.name;
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- Debug.Log("Exit Name: " + eventData.pointerCurrentRaycast.gameObject.name);
- Debug.Log("Exit Tag: " + eventData.pointerCurrentRaycast.gameObject.tag);
- Debug.Log("Exit GameObject: " + eventData.pointerCurrentRaycast.gameObject);
- mouseOver = false;
- gameObjectDetected = eventData.pointerCurrentRaycast.gameObject.name;
- }
- bool mouseOver = false;
- string gameObjectDetected = null;
- void Update()
- {
- if (mouseOver)
- {
- //Do something with gameObjectDetected
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement