Unity Input input class finger touch detection

On mobile devices, users typically interact using a touchscreen. Unity provides the Touch class to obtain the user's touch input. The following codes are some methods and parameters for getting touch: 

The following code demonstrates how to detect if the user has touched a finger on the screen:

 

In the above code, we used the Input.touchCount property to detect the number of fingers currently touching the screen. If there is a finger touching the screen, we use the Input.GetTouch method to get the first touch object, and then check whether its state is TouchPhase.Began, that is, the state where the finger starts to touch the screen.

In addition to TouchPhase.Began, the Touch class also has states such as TouchPhase.Moved, TouchPhase.Stationary, TouchPhase.Ended, TouchPhase.Canceled, etc., which are used to indicate the movement, rest and departure of the finger on the screen, and the cancellation of tracking due to system reasons. .

Here is the code:

 

Guess you like

Origin blog.csdn.net/qq_36592993/article/details/130593358