I am working on Android and have the following touch-driven interactions in Update:
void Update()
{
if (Input.touchCount == 1)
{
thisTouch = Input.GetTouch(0);
if (thisTouch.phase == TouchPhase.Moved)
{
if (Mathf.Abs(thisTouch.deltaPosition.y) > 16.0f || Mathf.Abs(thisTouch.deltaPosition.x) > 16.0f)
{
hasMovedThisTouch = true;
}
if (hasMovedThisTouch)
{
DoRotation(thisTouch.deltaPosition);
}
}
else if (thisTouch.phase == TouchPhase.Ended)
{
if (!hasMovedThisTouch)
{
DoClick();
}
hasMovedThisTouch = false;
}
}
else if (Input.touchCount == 2)
{
DoZoom(Input.GetTouch(0), Input.GetTouch(1));
hasMovedThisTouch = true;
if (Input.GetTouch(0).phase == TouchPhase.Ended && Input.GetTouch(1).phase == TouchPhase.Ended)
{
hasMovedThisTouch = false;
}
}
transform.LookAt(target);
}
Which is basically: If one finger is touching and not moving, DoClick. If one finger is touching and moving, DoRotate. If two fingers are touching, DoZoom.
I also have a few buttons on my overlay canvas that affect objects in the scene. This causes a problem.
When I click a button, the next raycast is blocked. I believe that it is because an item in the GUI still has focus. I attempt to solve this by putting GUI.FocusControl(null); at the end of my Update, but this has no effect.
How do I keep my touch interactions prepared to raycast after a button has been pressed?