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

Writing the character code and connecting the PlayerInput class to it


The last stage of the character is its code class. The code class will receive input from the PlayerInput class we wrote earlier, so the character can be controlled through the input and filter out the type of GameObjects that collided with from the parent of that collider type.

Perform the following steps:

To start with, navigate to the Assets/Scripts folder and right-click on it. Select Create and then C# Script. Name it Character.

Next, we need to give our PlayerInput class a reference to our character. To perform this, navigate to the Assets/Scripts folder and double-click on the PlayerInput.cs file to open it.

At the top of the class, under the SimpleTouch struct, add the following code:

    public Character GameCharacter;

We also need to tie the function that will call GameCharacter when PlayerInput gets a new one. At the bottom of the CalculateTouchInput function, add the following code:

        if (GameCharacter != null...