- Home /
Question by
Pulkitguglani1011 · Nov 15, 2019 at 05:16 PM ·
input.touch
TouchPhase.Began is false even after a valid touch?
I am using a script to check whether a swipe is there or not but sometimes TouchPhase.Began is not detecting a touch. void IsSwiped() // function to check that player swiped or not {
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Debug.Log("Total Touches :"+Input.touchCount);
if (touch.phase == TouchPhase.Began)
{
startswipeX = Camera.main.ScreenToViewportPoint(touch.position).x;
// beginning of touch position
//### when we start a new touch sometimes this TOuchPhase.Began is false and hence startSwipeX will be 0 which convert left swipe to right swipe as swipe direction depends upon starting position of touch.
Debug.Log("Position of touch is :"+startswipeX);
}
if (touch.phase == TouchPhase.Ended)
{
endswipeX = Camera.main.ScreenToViewportPoint(touch.position).x; // position where touch ended
if ((startswipeX - endswipeX) > 0.1f) // if swiped from right to left
{
Debug.Log("Left Swipe");
// Debug.Log(startswipeX + " " + endswipeX);
isRotating = true;
StartCoroutine(RotateRoomLeft(true));
startswipeX = 0;
endswipeX = 0;
}
else if ((startswipeX - endswipeX) < -0.1f) // if swiped from left to right
{
Debug.Log("Right Swipe");
// Debug.Log(startswipeX +" "+ endswipeX);
isRotating = true;
StartCoroutine(RotateRoomRight());
startswipeX = 0;
endswipeX = 0;
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612214845im_/https://answers.unity.com/themes/thub/images/avi.jpg)