Version: 2019.1
public int pointerId ;

説明

Identification of the pointer.

When using a mouse the pointerId returns -1, -2, or -3. These are the left, right and center mouse buttons respectively. When using touchscreen on mobile versions (such as iPad, iPhone, or Android), touches go from 0 up to however many touches the device supports.

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; } } }