I have two scripts, one is attached to the enemy called enemyhealth, and a script attached to the projectile called changehealth. This is the changehealth script:
function OnCollisionEnter (myCollision : Collision) {
if(myCollision.gameObject.name == "enemy"){
var health : enemyhealth = myCollision.gameObject.GetComponent(enemyhealth);
health.HP = HP - 5;
}
}
and this is the enemyhealth script:
var HP : int = 5;
function Update () {
if(HP < 0) {
DestroyObject (gameObject);
}
}
The only problem is that the changehealth script cannot access the HP value of the enemyhealth script. I can’t figure out how to fix it. What do I do?