- Home /
 
               Question by 
               ChocopopGames · Jan 09, 2014 at 06:44 PM · 
                javascriptplayerenemyattackhealth  
              
 
              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);
     }
  }
               Comment
              
 
               
              Answer by winch.91 · Jan 09, 2014 at 07:38 PM
have you declared TakeDamage as true? if so the enemy will take damage until you exit collision..
Your answer
 
 
             Follow this Question
Related Questions
How to make my player not lose health when attacking the enemy? 2 Answers
Damage script is screwed up...? what to do? 1 Answer
I need some health with my health/enemy script 0 Answers
Attacking enemys 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                