When the player begins to toss the ball, they'll touch and drag it in a flick gesture. We can add that now to the script.
Add the following to the top of the class:
private Vector3 inputPositionCurrent; private Vector2 inputPositionPivot; private Vector2 inputPositionDifference; private RaycastHit raycastHit;
Add the OnTouch function:
void OnTouch() { inputPositionCurrent.z = ballStartZ; newBallPosition = Camera.main.ScreenToWorldPoint(inputPositionCurrent); transform.localPosition = newBallPosition; }
Update(), on each frame, handles user input. Note that we use the UNITY_EDITOR directive variable to conditionally include code for input via mouse versus input via mobile screen touch:
void Update() { bool isInputBegan ...