Answer the question
In order to leave comments, you need to log in
How do you implement swipes in unity?
I tried in many ways, and universal for PC and Android through MousePosition, iDragHandler, touch.deltaPosition and separately counting the difference between positions. The variant with touch.deltaPosition seemed the most correct
void Update () {
Touch touch = Input.GetTouch(0);
if(touch.deltaPosition.x>0f){
Debug.Log ("right");
}
if(touch.deltaPosition.x<0f){
Debug.Log ("left");
}
}
Answer the question
In order to leave comments, you need to log in
if you all did this, then it’s not surprising ..
the general principle of the “swipe” gesture
is to remember the starting position (click / touch it doesn’t matter here)) plus maybe a timer and a finger / touch index if you need a multi-touch
- count the offset until you release it
- at the moment you release it - calculate the offset. (it is possible to check the time so that it does not count for a swipe if "led to the side for five seconds")
- the calculated offset. depending on the direction, count for the desired "swipe"
and not every frame as you count))
The wheelbarrow has phases. start. motion. cancellation. end... see the documentation.
as the mouse actually has - PRESSED. CLAMPED. RELEASED ))
https://docs.unity3d.com/ScriptReference/Touch-pha...
https://docs.unity3d.com/ScriptReference/Input.Get...
and so on
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question