Game Development Reference
In-Depth Information
Step 13: Build a simple KillPlayer function:
var health : int;
private var healthLevel : GameObject;
function Awake (){
healthLevel = GameObject.Find(“HealthLevel”);
}
function Start(){
health = 100;
healthLevel.guiText.text = health.ToString();
}
function ApplyDamage (damage : int){
health -= damage;
healthLevel.guiText.text = health.ToString();
if (health <=0){
KillPlayer ();
}
}
function KillPlayer(){
Application.LoadLevel(“Scene-ClosingFail”);
}
Why?
We haven't built Scene-ClosingFail yet, but the KillPlayer function loads it.
Things That Hurt
What we've built so far is an engine that keeps track of what the health level is
for the player. But we need to now create things that will hurt the player. We're
going to create a couple of things that do this. The first will be a trigger that we
place where the player shouldn't be (like where the water is or in the empty
space in the tall hall of stairs). Then, if the character collides with these triggers,
the trigger will send a message to the object that has collided with it (the
FPC_AegisChung) that the player has sustained damage, and how much damage
he's taken. For this mechanism we'll even build in a timer so that if the player
remains in the trigger (like in the icy water), the damage amount increases.
The second mechanism we'll build is using particles. There are lots of pipes in
the hallways; we'll have some steam leaks pop out, and if the player walks too
close to the steam, he'll incur damage.
Creating the Damage Triggers
Step 14: Create a new trigger that encompasses all the areas where the
player may come in contact with the water ( Figure 17.7 ). Note that it
goes off the front of the dock, but also includes the channel. Make sure
 
Search WWH ::




Custom Search