My health system isn't working. It's supposed to when the enemy enters the trigger, take 1 point off of your health, and ignore collisions between the enemy and you for 3 seconds- however, nothing is happening at all.
Here's the script on the trigger child of the main character:
var ColliderObj : GameObject;
function OnTriggerEnter(other : Collider) {
if (other.CompareTag("Enemy")) {
/// Calls the function ApplyDamage with a value of 5
gameObject.BroadcastMessage ("ApplyDamage", 1);
Physics.IgnoreCollision(ColliderObj.collider, other.collider);
yield WaitForSeconds(3);
Physics.IgnoreCollision(ColliderObj.collider, other.collider, false);
}
}
and here's the one on the parent object :
var hitPoints = 3;
var leveltoload = 1;
function Start(){
hitPoints = 3;
}
function Update(){
print(hitPoints);
}
function ApplyDamage (damage : int) {
if (hitPoints <= 0)
return;
if(hitPoints == 0)
Die();
hitPoints -= damage;
}
function Die(){
Application.LoadLevel(leveltoload);
}
Help!