enemy not deing

hi i’am making an fps game i’ave got everything sorted but the damage script, i’ave tried the standard packages one but that isn’t working. i’ave got the code here

flood is the enemy btw

function Start (){

if (Collision.GameObject.name == “Flood”){

Destroy(GameObject.Find(“Flood”));

}

}

2 Answers

2

Your function is called start. This means that as soon as the script starts, it checks if the bullet and the other object are colliding, but then it doesn’t ever check again. Change function Start to be function Update. This should solve your problem.

humm , that would seem to solve my problem but the enemy is still alive.

Is this script attached to the enemy? Is so try something like this and let me know what happens:

function OnCollisionEnter(object : Collision) {
   if(object.collider.name == "Bullet"){
      Destroy(object);
      Destroy(gameObject);
    }
}

I haven’t tested this, but give it ago.

---- Update ----

I’m assuming your player fires bullets already.

On your bullet, make sure it has a tag called “Bullet” as well as a collider, also make sure your flood (enemy) also has a collider.

In the script attached of your enemy, you want something like this:

function OnCollisionEnter(object : Collision){
   if(object.gameObject.tag == "Bullet"){
      print("Bullet has hit us (enemy)");
      Destroy(gameObject);
    }
}

i'ave got an error in that script trying to fix it....

i did change a few things to make it work..... var gameobject : Transform; function OnCollisionEnter(object : Collision) { if(object.collider.name == "Bullet"){ Destroy(gameobject); } }

Is this script attached to your Flood or Player? I dont have much info to go on?! Is the damage control for your player or enemy (flood)?

the damage is for the enemy and it's attached to the enemy

Okay - I've updated my answer ^. Try that out.