Unity's Input engine has a property called Input.touches, which is an array of Touch objects. The Touch struct contains information on the touch that occurred, having information such as the amount of pressure on the touch and how many times you tapped the screen. It also contains the position property, such as Input.mousePosition, that will tell you what position the tap occurred at, in pixels.
For more info on the Touch struct, check out https://docs.unity3d.com/ScriptReference/Touch.html.
Let's look at the steps to use touch instead of mouse inputs:
- Adjust our preceding code to look something like the following:
//Check if Input has registered more than zero touches
if (Input.touchCount > 0)
{
//Store the first touch detected.
Touch touch = Input.touches[0];
// Converts to a 0 to 1 scale
var worldPos = Camera.main.ScreenToViewportPoint
(touch.position);
float xMove = 0;
// If we press the...