i have a simple script that when it collides with a gameobject it loses health but the problem is that every enemy in the game with the same script losses health. i know why this is happening but i dont know how to fix it, any helppp!!
static var health:float = 10;
var damage1:float=3;
var damage2:float=1;
var damage3:float=15;
var damage4:float=1000;
var takedamage=true;
var afterobject:Transform;
function OnCollisionEnter(other : Collision) {
if (other.gameObject.tag == "bullet"){
if(takedamage){
//im sure the problem is here i tried puting gameObject.health but that didnt work
health-=damage1;
}
}
else if (other.gameObject.tag == "bullet2"){
if(takedamage){
health-=damage2;
}
}
else if (other.gameObject.tag == "bullet3"){
if(takedamage){
health-=damage3;
}
}
else if (other.gameObject.tag == "bullet4"){
if(takedamage){
health-=damage4;
}
}
}
function Update(){
if (health <= 0){
if(takedamage){
var bullit = Instantiate(afterobject, gameObject.transform.position, Quaternion.identity);
CPH.exp +=100/CPH.level;
monsterspawn.total -=1;
takedamage=false;
DestroyObject (gameObject);
}
}
}
change your static var for health to a public var and give it another try. If that doesn't work then can you please properly format all of your code so it's easier to read. Assuming it's all one script.
ā anon61858128