I have two if statements in my update loop. One for a single finger touch and another for a two finger touch. With one finger I am placing and dragging a gameobject. Then with two fingers in a pinch motion, I am scaling the gameobject. The problem is that when I try to touch the screen with two fingers, I usually trigger the one finger function first, causing me to accidentally place the gameobject before being able to scale it.
This script handles the single finger touch. I have a separate script that handles the two finger touch actions.
The only way to prevent this is to touch the screen with both fingers at the exact same time. How can I add some room for error so that when trying to touch the screen with two fingers, even if one finger touches the screen slightly before the other, the one finger action isn’t executed? Thank you.
if (Input.touchCount > 1 && m_HitTransform != null)
{
twoFingers = true;
}
else if (Input.touchCount == 1 && m_HitTransform != null && twoFingers == false)
{
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(0))
{
//code to place and drag gameobject
}
}
if (Input.touchCount == 0 && m_HitTransform != null) //no touches
{
twoFingers = false;
}
}