- Home /
swipe repeating more then once
hi there is a slight problem in this code swipe is working with out releasing my finger but it is working more then once when i swipe my finger and stop with out releasing and swipe again with out releasing my finger then action is repeating twice can any one fix this problem action should be once per swipe with out releasing my finger here is the following code that i used
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.Moved)
{
//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;
}
}
}
Answer by hirenkacha · Dec 10, 2013 at 08:14 AM
TouchPhase.Began
is called each frame you move your touch. Thats why it is called every time you keeping on swipe. Use TouchPhase.Ended
instead. so that it will call when you finished with your swipe.
if i use TouchPhase.Ended then swipe will function after i released touch i want swipe to be function with out releasing touch only once eg...link text
like this game
if u want to use swipe in move phase, then use touch.deltaposition to move the object on swipe.
thanks for your reply i am new to the touch can you please explain me how to use touch.deltaposition