Created
May 13, 2021 21:51
-
-
Save mstfmrt07/c23551110b7000e15718fef7aae027d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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