How can we know when user has stopped dragging fingers over screen if user has not removed finger from screen but stopped dragging ?
2 Answers
Check if Touch
TouchPhase
is Stationary
, which even says will be set only if:
A finger is touching the screen but hasn't moved.
I suggest you also read up on the Touch.phase
property, which exposes the TouchPhase
for the specific Touch
. The link also has examples on how to use the phase
.
The other option is to check the deltaPosition
of the Touch
.
If deltaPosition.x == 0 && deltaPosition.y == 0
, then the user has stopped dragging.
It would be great if your question was more specific, like dragging a game object or something. However you can use Interface to solve the problem. The demo code is given here. If you have questions regarding how to use it feel free to ask.
using UnityEngine;
using UnityEngine.EventSystems;
public class AnswersManager : IBeginDragHandler,IEndDragHandler,IDragHandler
{
public void OnBeginDrag(PointerEventData eventData)
{
//When Dragging Started
}
public void OnDrag(PointerEventData eventData)
{
// When Player is dragging
}
public void OnEndDrag(PointerEventData eventData)
{
// What to do when drag is completed
}
}
-
\$\begingroup\$ The problem with this thing is we do not get OnEndDrag till user lift up finger from screen...The solution was to check if TouchPhase is stationary as suggested by @joltmode \$\endgroup\$– idurveshFeb 7, 2016 at 16:15