Complete the code to check if the screen is touched.
if (Input.[1] > 0) { Debug.Log("Screen touched"); }
The Input.touchCount property returns the number of touches currently on the screen.
Complete the code to get the position of the first touch on the screen.
Vector2 touchPos = Input.touches[[1]].position;The first touch is at index 0 in the Input.touches array.
Fix the error in the code to detect if the first touch just began.
if (Input.touches[0].[1] == TouchPhase.Began) { Debug.Log("Touch started"); }
The phase property tells the current state of the touch, such as began, moved, or ended.
Fill both blanks to create a dictionary mapping fingerId to touch position for all touches.
var touchPositions = new Dictionary<int, Vector2>(); for (int i = 0; i < Input.touchCount; i++) { var touch = Input.touches[i]; touchPositions[touch.[1]] = touch.[2]; }
Each touch has a unique fingerId and a position on the screen.
Fill all three blanks to detect a swipe by checking if the touch moved more than 50 pixels.
if (Input.touchCount > 0) { Touch touch = Input.touches[[1]]; if (touch.phase == TouchPhase.[2]) { if (touch.[3].magnitude > 50) { Debug.Log("Swipe detected"); } } }
We check the first touch (index 0), see if it moved, and then check if the movement distance is greater than 50 pixels using deltaPosition.magnitude.