I use this script, but the enemy lose health if i don´t target him.

Can you sai me what can y add that makes that my script works well? There is my script

var health2 : Texture2D;
var health1 : Texture2D;
var texturewidth : int;
var textureheight : int;

function OnTriggerEnter(other : Collider){
    if(other.tag == "Player"){
        TakeDamage = true;
    }
}

function OnTriggerExit(other: Collider){
    if(other.tag == "Player"){
        TakeDamage = false;
    }
}

function Update(){
    if(TakeDamage){
         if(Input.GetButtonDown("Fire1")){
             health --;
       }
    }
  if(health <- -1){
    health = 0;
    Debug.Log ("ENEMY DOWN!");
Destroy(gameObject);
           
        }
        
        if(health == 100){
    Healthfull = true;
   }
}

function OnGUI(){
    if(health == 3)
    {
        GUI.Label(Rect(10,40,texturewidth,textureheight),healthfull);
    }
        if(health == 2)
    {
        GUI.Label(Rect(10,40,texturewidth,textureheight),health2);
    }
        if(health == 1)
    {
        GUI.Label(Rect(10,40,texturewidth,textureheight),health1);
    }
 }

have you declared TakeDamage as true? if so the enemy will take damage until you exit collision…