public int pointerId ;

描述

指针的标识。

使用鼠标时,pointerId 会返回 -1、-2 或 -3。这些值分别对应鼠标左键、右键和中键。在移动版本(如 iPad、iPhone 或 Android)上使用触摸屏时,多点触摸的范围是从 0 到设备支持的多点触摸数量。

using UnityEngine;
using UnityEngine.EventSystems;

/*To use the OnPointerDown, you must inherit from the IPointerDownHandler and declare the function as public*/ public class Test : MonoBehaviour, IPointerDownHandler { /*Called whenever a mouse click or touch screen tap is registered on the UI object this script is attached to.*/ public void OnPointerDown(PointerEventData eventData) { int clickID = eventData.pointerId;

if (clickID == -1) { Debug.Log("Left mouse click registered"); } else if (clickID == -2) { Debug.Log("Right mouse click registered"); } else if (clickID == -3) { Debug.Log("Center mouse click registered"); } else if (clickID == 0) { Debug.Log("Single tap registered"); } else if (clickID == 1) { Debug.Log("Double tap registered"); } else if (clickID == 2) { Debug.Log("Triple tap registered"); } } }
using UnityEngine;
using UnityEngine.EventSystems;

/*To use the OnPointerDown, you must inherit from the IPointerDownHandler and declare the function as public*/ public class Test : MonoBehaviour, IPointerDownHandler { /*Called whenever a mouse click or touch screen tap is registered on the UI object this script is attached to.*/ public void OnPointerDown(PointerEventData eventData) { switch (eventData.pointerId) { case -1: Debug.Log("Left mouse click registered"); break; case -2: Debug.Log("Right mouse click registered"); break; case -3: Debug.Log("Center mouse click registered"); break; case 0: Debug.Log("Single tap registered"); break; case 1: Debug.Log("Double tap registered"); break; case 2: Debug.Log("Triple tap registered"); break; } } }