Kill a Enemy - Answer

Very simple question that is solved by myself so if anyone want to use this code, feel free.

var life = 0;

function OnCollisionEnter(boom : Collision) {

    if(boom.gameObject.tag == "bullet")
    {
           life +=1;
           if(life == 50)
           Destroy(gameObject);
    }
    }

Make your weapon that hits the enemy have a tag “Bullet”. And then attach this script to your Enemy. You can change the Life == 50 to 25 to kill enemy faster or the Life +=1 to 5

THIS IS AN ANSWER
C#

  • Felipe

C# Version of the above code

  public int life = 0;
    
    public void OnCollisionEnter(Collision boom) 
    {
        //If the object that triggered this collision is tagged "bullet"
        if(boom.gameObject.tag == "bullet")
        {
               life +=1;
               if(life == 50)
               Destroy(gameObject);
        }
    }

I have a weapon that shoots and deals damage but i dragged script on a target bt it doesn’t die when i shoot anyway ._.