I am remaking my TouchScript making it faster and smarter but the swipe would only work Up or Right. It would show none if it needs to go Down or Left. It only gives Left/Right if both MoveX and MoveY are greater than SwipeSensivity, that too inverted like when it should give me Left it gives me down and vice versa. Heres my code: Code (CSharp): public enum SwipeTypes{None,Up,Down,Left,Right} public class TouchScript { [Tooltip("This mouse button will be used for taking input from the user")] public int MainMouseButton = 0; [Tooltip("This will be the touch index the script will use as Main Touch")] public int MainTouchIndex = 0; public float SwipeDistance = 50.0f; void MouseSwipe() { if(Input.GetMouseButtonDown(MainMouseButton)) { BeginPosition = Input.mousePosition; } else if(Input.GetMouseButtonUp(MainMouseButton)) { EndPosition = Input.mousePosition; Swipe = DetectSwipe(); } } SwipeTypes DetectSwipe() { float MoveX = EndPosition.x-BeginPosition.x; float MoveY = EndPosition.y-BeginPosition.y; Debug.Log(MoveX,MoveY); if(MoveY >= MoveX) { if(MoveY < -SwipeDistance) return SwipeTypes.Down; else if(MoveY > SwipeDistance) return SwipeTypes.Up; else return SwipeTypes.None; } else { if(MoveX < -SwipeDistance) return SwipeTypes.Left; else if(MoveX > SwipeDistance) return SwipeTypes.Right; else return SwipeTypes.None; } } Thanks
You should change: Code (csharp): if(MoveY >= MoveX) to: Code (csharp): if(Mathf.Abs(MoveY) >= Mathf.Abs(MoveX)) to check against absolutes. Right now, I could move 400 pixels to the left, and 1 pixel down, giving me a MoveY of 1 and a MoveX of -400, but you consider the MoveY a more significant move because 1 > -400.