private void StartSwipe(TouchEvent touchEvent) { Vector3 lookPosition; if (TouchUtils.TouchPositionToWorldCoords(touchEvent.GetEndPosition(), out lookPosition, 0.5f)) { swipeStarted = true; hero.CancelMoveToTarget(); hero.LookAt(lookPosition, attackTime); hero.StartSwipeAttack(); } }
private bool CheckForSwipeEnd(TouchEvent touchEvent) { float totalDistance = touchEvent.GetTouchEventPositionDelta().magnitude; if (totalDistance >= minSwipeDistance) { Vector2 startPosition = touchEvent.GetStartPosition(); Vector2 endPosition = touchEvent.GetEndPosition(); float minLengthAllowed = totalDistance - maxSwipeVarianceFromStraightLine; float maxLengthAllowed = totalDistance + maxSwipeVarianceFromStraightLine; foreach (TouchFrame frame in touchEvent.GetFrames()) { Vector2 framePosition = frame.GetPosition(); float frameDistance = Vector2.Distance(startPosition, framePosition) + Vector2.Distance(framePosition, endPosition); if (frameDistance < minLengthAllowed || frameDistance > maxLengthAllowed) { Debug.Log("Frame distance " + frameDistance + " outside of " + minLengthAllowed + " and " + maxLengthAllowed); return(false); } } return(true); } return(false); }