Book Image

Learning Unity iOS Game Development

Book Image

Learning Unity iOS Game Development

Overview of this book

Table of Contents (14 chapters)
Learning Unity iOS Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
6
Main Menu, iAds, Leaderboards, Store Purchases, and Achievements
Index

Input for the Touch device


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...