Book Image

Mastering Unity 5.x

By : Alan Thorn
Book Image

Mastering Unity 5.x

By: Alan Thorn

Overview of this book

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.
Table of Contents (16 chapters)
Mastering Unity 5.x
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Health and damage


Next up, we consider health and damage. Health is an interesting property, especially because it is abstract. That is, many characters have health: the player character and enemies, including the zombies. Though zombies are neither alive nor dead, but are undead, they still normally have an equivalent metric corresponding to health. When that property or resource is exhausted for any character, they expire, die, or are removed from the game. Because of the generic quality of health, it's a good idea to code it once such that it can be applied limitlessly as a component to any entity that has that property. For this reason, we'll create a Health class. Consider the following full source code and the comments that follow it:

//------------------------------------ 
using UnityEngine; 
using System.Collections; 
using UnityEngine.EventSystems; 
using UnityEngine.Events; 
//------------------------------------ 
public class Health : MonoBehaviour...