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

Starting to work with Update


Next, we will set up the Update function to look after any touch input from the user. In order to do this so that it works in the editor and on the device, we will need a bit of logic to repeat itself. This is because the mouse input isn't related to the touch input.

To begin, add the following code to the Update function:

  void Update () 
  {
    if (Application.isEditor)
    {
      if (Input.GetMouseButton(0))
      {
      }
    }
    else
    {
      if (Input.touches.Length > 0)
      {
      }
    }
  }

In this comparison, we will check whether the game can run in the editor. If it is not, we run what is in else.

If isEditor is true, we then check whether MouseButton(0) is pressed. Otherwise, as most people know, left-click on it.

If isEditor is false, we can check whether touches.Length is more than zero. If it is more than zero, we know that there is a touch on the screen.

Furthermore, you can also use platform-dependent conditions to check for specific...