need help for lost of heath

hi i am making a shooting game i can not get my enemy to lost heath and die this that i have so far

#pragma strict

static var healtha : int = 0;
var collided : boolean = false;
var healthguitext : GUIText;
var Bullet : GameObject;
var damage = 10;
var Enemy : GameObject;
var health : int = 10;

function OnCollisionEnter (col : Collision) {
col.gameObject.BroadcastMessage(“ApplyDamage”, damage, SendMessageOptions.DontRequireReceiver);
if(healtha)
Destroy(gameObject);
}

  1. When posting a question, use the “code” button (“101/010” icon) so it gets formatted correctly.
  2. You almost certainly don’t need a static variable (healtha). I recommend removing the static keyword if that makes sense in your case.
  3. Read through the example on the BroadcastMessage page.
  4. Since this script has “healtha” it suggests that it’s intended to be attached to the enemy. But in OnCollisionEnter() you’re destroying the gameObject and sending ApplyDamage to the other object, which suggests it’s intended to be attached to the bullet. Use comments to clarify for your readers.

Let’s say it’s attached to the bullet. In this case, you need another script on your enemy that accepts the ApplyDamage() message. Something like:

function ApplyDamage(damage : float) {
    health -= damage;
    healthguitext.text = "Health: " + health;
    if (health <= 0) {
        // Enemy just died.
        healthguitext.text = "DEAD";
    }
}