Please, I need a damage script

Hi, I've been trying to make a script to damage my NPC's they already have hitpoints and health but I can't do any damage to them. If someone could be kind enought to paste one as an anwsere or reply it would help me alot. Thatk's for your time and good luck with unity!

Yes, I am quite new to unity.

See the FPS Tutorial for a detailed explanation.

A simple example.

The enemy script.

var damage = 10;

function OnCollisionEnter (col : Collision) {
    col.gameObject.BroadCastMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}

player script:

var health = 50

function ApplyDamage (damage : int) {
     health -= damage;

     if(health <= 0) {
         Die();
     }

function Die () {
   //Die and or Respawn
}

static var health : int = 0;
var collided : boolean = false;
var healthguitext : GUIText;

function Start(){
health = 10;
}
 
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.collider.gameObject.tag == "(name of object here)") {
LessDamage();
}
}
 
function Update(){
healthguitext.text = health.ToString();
}
 
 
function LessDamage(){
if(!collided) {
health--;
collided = true;
yield WaitForSeconds(1);
collided = false;
}
}

just replace the (name of object by the name of the object you want to apply damage to.