Skip to content

Instantly share code, notes, and snippets.

@mstfmrt07
Created May 13, 2021 21:51
Show Gist options
  • Save mstfmrt07/c23551110b7000e15718fef7aae027d0 to your computer and use it in GitHub Desktop.
Save mstfmrt07/c23551110b7000e15718fef7aae027d0 to your computer and use it in GitHub Desktop.
public void OnDrag(PointerEventData eventData)
{
if (draggingStarted)
{
endPos = eventData.position;
Vector2 difference = endPos - startPos; // difference vector between start and end positions.
if (difference.magnitude > swipeThreshold)
{
if (Mathf.Abs(difference.x) > Mathf.Abs(difference.y)) // Do horizontal swipe
{
direction = difference.x > 0 ? Direction.Right : Direction.Left; // If greater than zero, then swipe to right.
}
else //Do vertical swipe
{
direction = difference.y > 0 ? Direction.Up : Direction.Down; // If greater than zero, then swipe to up.
}
}
else
{
direction = Direction.None;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment