一个Unity朋友突然间让我做这么一个功能,有点懵,花了大概是10分钟左右写出来的,需要注意的是继承IPointerDownHandler 这个接口。OnPointerDown 是这个接口的实现。UnityEngine.EventSystems 引用这个命名空间
private bool MouseCilcking = false;
public PointerEventData.InputButton MouseType;
void Update()
{
if (Input.GetMouseButtonUp((int)MouseType))
{
Debug.Log("鼠标松开了");
MouseCilcking = false;
}
if (MouseCilcking)
{
Debug.Log("鼠标点击了UI,并且鼠标没有松开");
}
}
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.button == MouseType)
{
Debug.Log("鼠标点击了本UI");
MouseCilcking = true;
}
}