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

What is Touch?


Touch is a struct. To put it differently, it is a group of different variables that hold information about what the input can do. It is possible to monitor multiple Touch structs at once if the user is trying to input more than one, although we are only looking for one.

We do not need all the information Unity's touch gives us. We only need the location on the screen where the touch started, how long the touch lasted in seconds, where the touch ended on the screen, and the current state of the touch. From this, we will be able to detect the type of input and the direction of the input, if the player tapped, or if the player swiped in a direction.

Our own Touch

The first step to coding our input class is to create our own struct that will hold the values we need. The benefit to creating our own Touch is that we can then use it for only what we need. It also gives us the means to use the mouse input to accomplish the same input logic as the device, allowing editor testing that...