Unity检测鼠标进入、离开UI检测
引用命名空间
UnityEngine.EventSystems
IPointerEnterHandler:进入
IPointerExitHandler:离开
注意:Image需开启RaycastTarget
using UnityEngine;
using UnityEngine.EventSystems;
public class IPointer_Handler_Test : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public GameObject obj;
/// <summary>
/// 鼠标进入UI
/// </summary>
/// <param name="eventData"></param>
public void OnPointerEnter(PointerEventData eventData)
{
obj.SetActive(true);
}
/// <summary>
/// 鼠标离开UI
/// </summary>
/// <param name="eventData"></param>
public void OnPointerExit(PointerEventData eventData)
{
obj.SetActive(false);
}
}