Quantcast
Channel: Latest Questions by zeuo
Viewing all articles
Browse latest Browse all 90

how to make the player damage one enemy

$
0
0

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

}

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>