To calculate the type of touch from the touch input, we will follow the same logic. We will only use the touch location to calculate StartTouchLocation
and CurrentTouchLocation
.
Add the following code in the else
block of the Update
function, after Application.isEditor
and in if Input.touches.Length > 0
:
if (Input.touches.Length > 0) { DeviceTouch = Input.GetTouch(0); if (ActiveTouch.Phase == TouchPhase.Canceled) { ActiveTouch.Phase = DeviceTouch.phase; ActiveTouch.StartTime = System.DateTime.Now; ActiveTouch.StartTouchLocation = DeviceTouch.position; ActiveTouch.CurrentTouchLocation = DeviceTouch.position; } else { ActiveTouch.CurrentTouchLocation = DeviceTouch.position; } }
As you can see, this follows the same concept as what we do for when the game is running in the editor. The big difference being that we will now assign DeviceTouch
to Input.GetTouch(0)
when there is more than one touch active...