- Home /
Problem with enemy health.
I have scripts: (in Missile)
void OnCollisionEnter(Collider
collision) { if
(collision.gameObject.name ==
"ZombieSpawn(Clone)"){ EnemyFight
efight =
collision.GetComponent<EnemyFight>();
efight.DecaraseHP(10);
} }
and something in EnemyFight (script)
public int enemyMaxHp = 10;
public int enemyHp = 10;
and
> public void DecaraseHP(int minusHP) {
> enemyHp -= minusHP;
}
What's mine problem? When i shoot to enemy a last created enemy take damage, not this enemy who are shooted by me. Please help me! :(
I searched on google but nothing works.
Please edit your quest so it contains source code as it is in your project.
At the moment it appears to have forced line breaks and ">" quote indents like it has been emailed.
This makes it hard for us to know the exact code you are working with and harder to provide assistance.
Answer by azmat786n · Dec 29, 2013 at 03:57 PM
you can use below scripts to do what you want.
missile script
public damage int = 10;
void OnCollisionEnter(Collision col) {
gameObject.GetComponent<enemyScript>().decreaseHealth(damage);
}
enemy script
public health int = 100;
public void decreaseHealth(int damage) {
health -=damage;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to get Enemy to break wall between it and Player. 1 Answer
Damage rate HELP 1 Answer
How to have an NPC with multiple parts detect damage 1 Answer