How to make your player health subtract when enemies come into contact with you

Hi, I am developing a FPS game where enemies come chasing after you.

I am having trouble developing a system where when the enemies come into contact with me, my health decreases.

Can someone kindly help me with the scripting how to do this, and how do I setup a GUI display for my health as well.

Thank you very much.

Get distance using

distance = Vector3.Distance(ENEMY, PLAYER);

Check IF the distance is less than 1, than destroy the enemy chasing...

if(distance <= 1)
   //You can add in an animation to explode/whatever else you want when it hits the player.

ELSE, keep chasing.


I'd separate the GUI question, but their are tutorials on it. Check this guy out:

In my game I have a large monster that attacks with melee attacks. During melee attacks I create a box collider object around the monster's claw (the object is a child of the claw's bone). If the collider hits the player I have it deal damage and then destroy itself to avoid doing repeat damage. The collider also has a timer to destroy itself when the attack is over.

OnCollisionEnter(Collision col){
  if (col.tag == "enemy") {
      health-= col.gameObject.GetComponent<EnemyScript>().DamageAmt;
      // or maybe just health--;

you will have to add custom logic for what to do when your health reaches 0 of course.