- Home /
How to use TouchPhase.Ended?
Seems like a really a silly question but shockingly, I'm struggling quite a bit. I've been able to implement TouchPhase.Began and TouchPhase.Moved but I'm not sure how to use TouchPhase.Ended. The following code shows how I'm currently testing for it.
else if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
Debug.Log("IT HAS ENDED");
}
This part of my function never gets called and I assume it's because when a touch ends there's no Input. This might be relevant but this code is located in Update().
I do appreciate any and all comments so thank you for reading through and I hope you can help me. Edit: nvm, turns out i was nesting it incorrectly.
Answer by JavierRuidoRosa · Jul 11, 2018 at 09:21 AM
You can use the phase attribute to register the positions.
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
//Register the initial position
}
else if (touch.phase == TouchPhase.Moved)
{
//Move things using deltaPosition or something else
}
else if (touch.phase == TouchPhase.Ended)
{
//Register the final position and check if the distance is enough to consider a swipe.
}
You can also register the initial and final time, so if the time between the start and the end of the touch is too little, you don't consider it a swipe.
I hope this helps!
@JavierRuidoRosa thanks for the solution!! However, I'm having trouble implementing the TouchPhase.Ended bit. I've edited my code, please take a look if it's not too much trouble.
Ok, try these things:
$$anonymous$$ake sure that conditional is not inside another conditional checking a different phase.
Comment all code except that conditional to test it.
Save the touch in a variable before checking its phase, like in my example.
Let me know if this works :)
Oh, I just read the edit. I'm glad you solved your problem! ;D
Your answer
Follow this Question
Related Questions
Make object follow my finger (Touch)? 1 Answer
TouchScreenKeyboard textfield move focus 0 Answers
Touches on the far left side not registering due to 3D Touch app switching 0 Answers
define touch area 2 Answers
toucscreen features for mobile in unity can be integrate to a touchscreen monitor? 1 Answer