i am trying to do swipe functionality for android phone and the code is working but i am facing a problem when i am swiping and removing my finger then it is doing action or else with out removing my finger on device the action can not be done what i want to do can any one help me with this here is my code
if(Input.touches.Length > 0)
{
Touch t = Input.GetTouch(0);
if(t.phase == TouchPhase.Began)
{
//save began touch 2d point
firstPressPos = new Vector2(t.position.x,t.position.y);
}
if(t.phase == TouchPhase.Ended)
{
//save ended touch 2d point
secondPressPos = new Vector2(t.position.x,t.position.y);
//create vector from the two points
currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);
//normalize the 2d vector
currentSwipe.Normalize();
//swipe upwards
if(currentSwipe.y > 0 && currentSwipe.x > -0.8f && currentSwipe.x < 0.8f)
{
lastJumpButtonTime = Time.time;
}
}
}
Your question is not really clear, I will assume that you want the swipe to be activated without releasing the touch, see my answer below. Also you should remove some blank line in your code for better readability.
– PhilRousse