[ad_1]
I’m making an attempt to create a gesture handler that may detect each swipes/pans – inside one contact – in Unity. I ought to give you the option, inside one contact occasion, to pan slowly to the left or proper. During the identical contact, with out lifting my finger, I ought to be capable to then swipe to the left or proper. How do I do that? Here is my code under.
non-public void Update() {
if (Touch.activeFingers.Count == 1)
{
swipeAllowed = true;
var contact = Touch.livelyTouches[0];
// all collected touches should be transformed to display screen -> world level for use in calculations
if (contact.section == TouchSection.Began)
{
startPos = Camera.predominant.ScreenToWorldPoint(contact.screenPosition);
StartCoroutine(CheckForAnimation(contact));
}
if (contact.section == TouchSection.Stationary)
{
DragAndDrop(contact);
}
if (contact.section == TouchSection.Moved)
{
Debug.Log("moved");
currentPos = Camera.predominant.ScreenToWorldPoint(contact.screenPosition);
StartCoroutine(DragOrSwipeCamera(startPos, currentPos, contact));
}
}
}
IEnumerator DragCamera(Vector3 startPos, Vector3 currentPos, Touch contact)
{
distance = currentPos - startPos;
var velocity = (float) (Vector3.Distance(currentPos, startPos) / (contact.time - contact.startTime));
// PSEUDOCODE: Based on velocity, determine whether or not it needs to be a drag or a swipe? Not certain what to do right here?
yield return null;
}
````
[ad_2]