Book Image

Getting Started with Unity

By : Patrick Felicia
Book Image

Getting Started with Unity

By: Patrick Felicia

Overview of this book

<p>Unity is a game development engine which is fully integrated with a complete set of intuitive tools and rapid workflows used to create interactive 3D content. Unity is best used for making great games that can deploy to numerous platforms.</p> <p>"Getting Started with Unity" guides you progressively through the necessary steps to create a survival game using Unity3D&rsquo;s built-in objects and components, JavaScript, animations with Mecanim, and some basic AI.</p> <p>In this book, you will be introduced to a wide range of the core features used for games developed with Unity3D, including the user interface and much more. Furthermore, you will also learn about essential aspects like transformations, scripting, navigation, and built-in controllers.</p> <p>Beginning with an introduction to the user interface, you will learn the necessary skills required to create a survival video game. Each section is a stepping-stone toward the completion of the final game. By the end of the book, you will have created an indoor level with enemies, AI, weapons, objects to collect, and all the logic to control the game.</p>
Table of Contents (13 chapters)
Getting Started with Unity
Credits
About the Author
About the Reviewer
www.packtpub.com
Preface
Index

Displaying the health bar


At present, the player's health is saved in the script collisionDetection; however, it is not represented on the screen. We will create a new script that displays a health bar symbolized by a rectangle in the top-left corner of the screen. Its length will be proportional to the player's health (that is, ranging from 0 to 100 percent), and the color will also vary accordingly. For example, it will be green when the health is between 67 percent and 100 percent, orange when the health is between 33 percent and 67 percent, and red when the health is between 0 percent and 33 percent. These visual cues will help the player to judge when it is time to look for and collect med packs. Follow these steps to display the health bar:

  1. Create a new folder labeled Scripts by selecting Assets | chapter4.

  2. Create a new script (JavaScript) inside this folder, rename it HealthBar, and add the following code to it:

    private var  currHealth : int = 45;
    private var currentColor:Texture2D;...