Enemy health and damage script help-->Getting and changing hp value/death

I used my knowledge so far to make a one bullet enemy damage system which is really just silly,because it has no realism or it doesnt make any sense to kill my enemy so fast.So I have made 2 new script which I want to use as enemy health/damage system for multiple guns.I only have this so far:
Enemyhp script:

var hp :int;

function die(){
Debug.Log("Enemy Killed");
}

function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.tag == "Bullet")
    {
     
    }
}

And my bullet damage script:

var damage:int;
function DoDamage(){


}

function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.tag == "Enemy");
    {
      DoDamage(); 
    }
}
}

My question is,how would I change the enemy hp by getting the values of the hp and reduce it?And how would I check if my enemy has 0 hp left?

something like that ? sorry for my bad Unity/Javascript, i’m more in c#

EnemyScript

var hp :int;
function Die(){
Debug.Log("Enemy Killed");
}
function ApplyDamage(_damage : int){
     if(hp > 0) {    
          hp -= _damage;
          if(hp <= 0) {
               hp = 0;
               Die();
          }
     }
}

BulletScript

var damage:int;
function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.tag == "Enemy");
    {
      col.gameObject.GetComponent("EnemyScript").ApplyDamage(damage);
    }
}
}
1 Like

That is the way to go…
Thanks for the help!