Version: 2019.2
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; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961