Game Development Reference
In-Depth Information
Figure 17.4 Making sure that the
Scene-Closing is part of the scenes
that Unity knows to play.
Tutorial 17.2: Health Systems
As usual in Unity, there are several ways to approach a health system. We're
going to approach it in the most common way and create a health engine
that is attached to FPC_AegisChung. This health engine is really just a counter.
It will start knowing that the health of the character is 100 (or whatever).
Then, as the character comes in contact with certain situations (gets hit by
a bullet, has a rock dropped on him, steam hits him, falls too far—use your
twisted imagination here), a message will be sent to this health engine to
subtract from whatever the health value is. When the health equals 0, fire a die
function to alert the player that he's kicked the bucket and lost the game.
So to begin, we'll need to create the health script.
Step 1: Create a new JavaScript. Name it HealthEngineScript
and open it.
Step 2: Define a couple of variables. One (an integer) will hold the actual
value of the health. The second (a GameObject) will hold the GUIText
GameObject that displays the health level:
var health : int;
private var healthLevel : GameObject;
Step 3: For now, we want to tell Unity that when the game starts, set the
health to 100 and then display that value:
var health : int;
private var healthLevel : GameObject;
Search WWH ::




Custom Search