Implementing a gesture

Another type of input that you'll find in mobile games is that of a swipe. This will allow us to use the general movement of the touch to dictate a direction for us to move in. This is usually used to have our players jump from one position to another or move quickly in a certain direction, so we'll go ahead and put that in, instead of our previous movement system:

  1. First, in the PlayerBehaviour script, go ahead and add some new variables for us to work with:
    [Header("Swipe Properties")]    [Tooltip("How far will the player move upon swiping")]    public float swipeMove = 2f;    [Tooltip("How far must the player swipe before we will execute the action (in pixel space)")]    public float minSwipeDistance = 2f;    /// <summary> 

Get Unity 2017 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.