Completely ignoring second touch

Hi,

Currently I handle touch and mouse movement using these handlers:
IPointerDownHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerUpHandler

When the user interacts with the screen I save the positions as seen below and then use these position variables later by other functions:

void OnDrag(PointerEventData eventData) {

        eventData_Screen = eventData.position;
        eventDataX_Screen = eventData.position.x;
        eventDataY_Screen = eventData.position.y;

}

How could I completely ignore every touch apart from the first one?

I tried using Input.touchCount == 1 like this:

void OnDrag(PointerEventData eventData) {

        if (Input.touchCount == 1) {
            eventData_Screen = eventData.position;
            eventDataX_Screen = eventData.position.x;
            eventDataY_Screen = eventData.position.y;
        }

}

but there are several problems with this:

  • it doesn’t work with mouse like this
  • when the second touch is received it disables the first touch’s movement too

I’m searching for a way to completely ignore the second touch and follow the first touch like nothing happened and like the second touch wouldn’t even exist.

Do you have any ideas how could this be achieved?

Thanks.

When the pointer is down you would need to record the eventData.pointerId and then make sure that all the other functions only react when their eventData.pointerId matches the one you recorded at the begining.

Do you need multitouch? If not, you can turn off multitouch by putting

Input.multiTouchEnabled = false; in Awake in any script. Usually in a startup scene.

3 Likes