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;
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";
}
}