话不多说。
1.点击具有Button属性的对象,在Inspector中点击“Add Component”>"Event">"Event Trigger",或在搜索框中直接搜索。
2.点击Event Trigger组件中的“Add New Event Type”>“PointerEnter”(鼠标进入)/“PointerExit”(鼠标滑出)/“PointerDown”(按下)/“PointerUp”(抬起)/“PointerClick”(点击)等。
3.创建脚本“ButtonEvent”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonEvent : MonoBehaviour {
void Start ()
{
}
void Update ()
{
if (m_down && Time.time - _time > 2f)//按下2秒属于长按
{
m_down = false;
Debug.Log("长按中");
}
}
public void MouseEnter()
{
Debug.Log("鼠标进入");
}
public vo