- Home /
clickable grid and pinch zoom
Hi,
I have a clickable grid (by touch) and need to make a pinch zoom, but my problem is that evertime if I try to pinch zoom, Unity gets the first finger touch and thinks it's also a click on the grid and is moving my player sprite.
Is there a way to check if it is a short tap or a pinch zoom gesture?
thanks in advance Frank
Create a small delay of 0.5 seconds before it assumes it is a click.
void Update()
{
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8
$$anonymous$$ouseEnabled = false;
if (!PlayerController.is$$anonymous$$oving && Input.touchCount == 1)
{
HandleInput();
}
#endif
}
this is how I check the tap. Could you give me an example for the delay check?
should have thought of this before. Create a new test to check if number of touches is 2.
void Update () {
if (Input.touchCount == 0)
return;
if (!PlayerController.is$$anonymous$$oving && Input.touchCount == 1)
{
HandleOneTouch();
}
else if (!PlayerController.is$$anonymous$$oving && Input.touchCount == 2)
{
HandleTwoTouch();
}
else if (!PlayerController.is$$anonymous$$oving && Input.touchCount == 3)
{
HandleThreeTouch();
}
else
{
}
}
The problem is, in the moment if I place 2 fingers on the device it recognizes first a Input.touchCount == 1 before is gets Input.touchCount == 2. It's impossible to touch with 2 fingers exactly at the same time.
Answer by DiebeImDunkeln · Jan 13, 2015 at 04:41 PM
I tried it, but that was not solving my problem.
I handle it now with a coroutine within the PinchZoom with a delay for a comeback. While Pinch is active the touch of the fields below are deactivate. After ending the pinch I active the fields again with a delay of 0.5 second.
Answer by hypnoticmeteor · Jan 10, 2015 at 11:53 AM
using UnityEngine;
using System.Collections;
public class MonitorTouch : MonoBehaviour {
int touchCount;
void Update()
{
touchCount = 0;
foreach (Touch touch in Input.touches)
{
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
touchCount++;
}
if (touchCount == 3)
{
//handle if 3 touches
}
if (touchCount == 2)
{
//handle if 2 touches
}
if (touchCount == 1)
{
//handle if 1 touch
}
}
}
Tried and tested.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180000im_/https://answers.unity.com/themes/thub/images/avi.jpg)