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

Wrapping up


The entire PlayerInput class should look similar to the following code:

using UnityEngine;
using System.Collections;
using System;

public class PlayerInput : MonoBehaviour
{
  public struct SimpleTouch
  {
    public Vector2 StartTouchLocation;
    public Vector2 CurrentTouchLocation;
    public DateTime StartTime;
    public TouchPhase Phase;
  }

  public float SwipeTime;
  public float SwipeDistance;

  private SimpleTouch ActiveTouch;
  private Touch DeviceTouch;

  private void CalculateTouchInput(SimpleTouch CurrentTouch)
  {
    Vector2 touchDirection  =
    (CurrentTouch.CurrentTouchLocation - 
    CurrentTouch.StartTouchLocation).normalized;

    float touchDistance = 
    (CurrentTouch.StartTouchLocation - 
    CurrentTouch.CurrentTouchLocation).magnitude;

    TimeSpan timeGap = 
    System.DateTime.Now - CurrentTouch.StartTime;

    double touchTimeSpan = 
    timeGap.TotalSeconds;

    string touchType =
    ( touchDistance > SwipeDistance 
    && touchTimeSpan...