https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.html
注意:非UGUI元素要响应事件,需要在 Camera 上添加 PhysicsRaycaster 组件。
using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; public class TestButton : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler { public void OnPointerClick(PointerEventData eventData) { } public void OnPointerDown(PointerEventData eventData) { } public void OnPointerUp(PointerEventData eventData) { } }