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

Attacking the enemy


Players tend to become frustrated quickly when faced with an enemy that they are unable to fight against. So, we are going to give our player the ability to damage and destroy the enemy tank. This will function in a similar manner to how the targets are shot.

The easiest way to weaken our enemies is to give them some health that will reduce when they are shot. We can then destroy them when they run out of health. Let's create a script with these steps to do this:

  1. We will start by creating a new script and naming it Health.

  2. This script is rather short and starts with a single variable. This variable will keep track of the remaining health of the tank. By setting the default value to 3, the tank will be able to survive three hits before being destroyed.

    public int health = 3;
  3. This script also contains only one function, Hit. As in the case of the targets, this function is called by the BroadcastMessage function when the player shoots at it. The first line of the function reduces...