Book Image

Learning Unity Android Game Development

By : Thomas Finnegan
Book Image

Learning Unity Android Game Development

By: Thomas Finnegan

Overview of this book

<p>Unity 5 is a revolution in developing great games for Android that provides a great integration platform that works seamlessly with Unity 5, which means that games can be developed quicker and easier than ever before.</p> <p>Packed with a lot of examples, this book starts by helping you to understand all the great features that Unity 5 and Android have to offer. You will then create great games like Tic-Tac-Toe and the Monkey Ball game and also learn to enhance them. You will then expand the game's environment with lights and a skybox and learn to create enemies in a tank battle game. You will then explore the touch and tilt controls with the creation of a Monkey Ball clone.</p> <p>With the recreation of a game similar to Angry Birds, you will delve into configuring physics and options for a 2D game experience. Finally, you will get a complete experience by learning the optimization techniques needed to keep your games running smoothly.</p>
Table of Contents (16 chapters)
Learning Unity Android Game Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Making the enemy chase the player


Our next task is to make our enemy tank chase the player. We will need two scripts for this. The first will simply advertise the player's current position. The second will use that position and the NavMeshAgent component that we set up earlier to find a path to the player.

Revealing the player's location

With a very short script, we can easily allow all our enemies to know the location of the player. A few short steps to create it are as follows:

  1. Start by creating a new script in the Scripts folder of the Project window. Name it PlayerPosition.

  2. This script will start with a single static variable. This variable will simply hold the current position of the player. As it is static, we will be able to easily access it from the rest of our scripts.

    public static Vector3 position = Vector3.zero;

    Note

    We chose to use a static variable here for its simplicity and speed. Alternatively, we could have added a few extra steps to our enemy tank; it could have used the FindWithTag...