1、首先继承IPointerEnterHandler、IPointerExitHandler等接口
2、实现其方法
如:OnPointerEnter、OnPointerExit文章来源:https://www.toymoban.com/news/detail-840928.html
注意:这些只对UI有效,而OnMouseEnter只对加Collider的非UI有效文章来源地址https://www.toymoban.com/news/detail-840928.html
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Slot : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
public Item slotItem;
public Image slotImage;
public Text slotNum;
public void OnPointerEnter(PointerEventData eventData)
{
BagManager.instance.itemDesc.text=slotItem.itemDesc;
}
public void OnPointerExit(PointerEventData eventData)
{
throw new System.NotImplementedException();
}
}
到了这里,关于[Unity]UI事件(鼠标进入、离开、点击)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!