Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

PointerEventData.pointerId

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public var pointerId: int;
public int pointerId;

Description

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.

no example available in JavaScript
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"); } } }
no example available in JavaScript
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; } } }

Did you find this page useful? Please give it a rating: