- Home /
              This post has been wikified, any user with enough reputation can edit it. 
            
 
            Make Health script lose health when certain animation is played?
I am trying to make my player lose health when the enemy attacks with a certain animation here is the health script i have.
 using UnityEngine;
 using System.Collections;
 
 public class Health : MonoBehaviour {
 
     private float maxHealth = 100f;
     public float curHealth = 100f;
     private float width = 150f;
     private float height = 35f;
     public GameObject Entity;
     public GUITexture HealthBar;
     // Use this for initialization
     void Start () {
         //Start of Health bar
         HealthBar.pixelInset = new Rect(Screen.width/-2.1f, Screen.height/2.25f, width, height);
 
     }
     
     // Update is called once per frame
     void Update () {
         //Percentage of health
         float per;
         per = curHealth/maxHealth;
         //New Bar Called when loss of health
         HealthBar.pixelInset = new Rect(Screen.width/-2.1f, Screen.height/2.25f,width * per, height);
 
         if (curHealth <= 0)
             curHealth = 0;
         
         if (curHealth <= 0) 
         {
             Destroy (Entity);
         }
     }
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Ngoc Ngo · Jul 07, 2014 at 09:12 AM
At the end of that animation, add an event which call a function somewhere which in turn decrease 'health' value in this script, and it may work.
Thanks i just decided to make it take of damage when the enemy is a certain distance away.
Your answer
 
 
             Follow this Question
Related Questions
A node in a childnode? 1 Answer
Strange behaviour of error CS0246 in Unity 1 Answer
Script Reference using C # 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Tracking Down GUI Errors 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                