Created
January 29, 2019 06:20
-
-
Save HassakuTb/2db32099edcec55e9f7d17d25f59733e to your computer and use it in GitHub Desktop.
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 characters
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(Graphics))] | |
public class MouseOverDetector : MonoBehaviour{ | |
[SerializeField] private GraphicRaycaster raycaster; // Required | |
[SerializeField] private EventSystem eventSystem; // Required | |
/// <summary> | |
/// マウスカーソルがこのUI上に存在するか | |
/// </summary> | |
/// <returns></returns> | |
public bool IsMouseOver() | |
{ | |
List<RaycastResult> results = new List<RaycastResult>(); | |
PointerEventData eventData = new PointerEventData(eventSystem); | |
eventData.position = Input.mousePosition; | |
raycaster.Raycast(eventData, results); | |
return results.Any(result => result.gameObject == gameObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment