if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { // Do something here }
switch (Input.GetTouch(0).phase) { case TouchPhase.Began: // Do something when touch is detected break; case TouchPhase.Moved: // Do something when touch is moved break; case TouchPhase.Stationary: // Do something when touch is stationary break; case TouchPhase.Ended: // Do something when touch is lifted off the screen break; case TouchPhase.Canceled: // Do something when touch is cancelled break; }This code uses a switch statement to check the current touch phase and performs different actions based on the phase.