- Home /
 
Zombie Health Script Not working??
OK so i tried making a zombie health script also for it to get damage from a projectile (NOT RAYCAST) but even though it doesn't show any arrows for some reason when i try to shoot the zombie it doesn't work. Hers the script if anyone could halp me out thanks a lot!!!!
The Script:
 var health : int = 100;
 var bullet : GameObject;
 var damage : int;
  
 function Update () 
 {
     if(health < 0)
     {
        Die();    
     }
 }
  
 function OnTriggerEnter ( hit : Collider ) 
 {
     Debug.Log("trigger");
     if(hit.gameObject.tag == "zombie")
     {
        bullet = hit.gameObject;
        TakeDamage(); 
     }
     if(hit.gameObject.tag == "zombie")
     {
        bullet = hit.gameObject;
        TakeDamage(); 
     }
 }
  
 function TakeDamage()
 {
     health -= damage;
 }
  
 function Die()
 {
 
     Network.Destroy(gameObject);
  
 }
 
               function TakeDamage()
 {
    Debug.log(health);
    health -= damage;
    Debug.log(health);
 }
 
                  make sure it's actually changing, if not then your trigger isn't activating.
Yeah, you need to throw some debugs to check if it is called.
Answer by Ermarrero · Apr 07, 2014 at 01:42 AM
Also not a biggie but this code:
 if(health < 0)
     {
        Die();    
     }
 
               change to :
 if(health <= 0)
     {
        Die();    
     }
 
               don't want a zombie with 0 health running around :)
Your answer
 
             Follow this Question
Related Questions
Destroy object on collision and update script. 2 Answers
Destroying a prefab on collision with a cube? 1 Answer
Trouble with raycast hitting a tagged object 0 Answers
Game Over GUI Question 2 Answers