title: UnityScript: Update Health Function
body: <p>The game I'm making has a character and enemy. When the character gets hit is closes health. If the character can avoid getting hit for 10 Seconds it regains 5 points of health. If another 10 seconds pass and he still does not get hit he gains another 5 points and this keeps on happening until the character regains full health. If the character get hits before the 10 seconds are completed he loses health and the time starts over. </p>
  
  <p>Currently when I run the C# script it does everything except keep giving health to the player. If I get hit it records the time. The 10 seconds pass and it gives me health but after that the <code>Update</code> function does not continue to give me health it just does it once. I think my logic somewhere is not correct. What you guys think ??   </p>
  
  <pre><code>public Slider healthBar;
  public float HitResetTimer; //Resetsthetimerto0whenihavebeenhitwithinthe10seconds;
  bool beenHit; //Return true or false if ihave been hit
  float hitTimer; //keeps track of time from 0 to 10 if i have not been hit
  
  void Awake()
  {
      beenHit=false; //player has not been hit so= false
      hitTimer=0.0f; //Set to 0 because i have not been hit yet so no time needs to be registered
  }
  
  void OnTriggerEnter(Collider other)
  {
      healthBar.value-=10;//If enemy hits character loses 10 points
      beenHit= true; //Is set to true because i have been hit
      hitTimer= HitResetTimer;//If cube hits something hitTimer is no longer time that has occured but reset to 0
  
  }
  
  void RestoreHealth()
  {
      if(!beenHit&amp;&amp; healthBar.value&lt;100)
          healthBar.value+=2;
  }
  
  //Usethisfor initialization
  void Start () {
  
  }
  
  //Updateiscalledonceper frame
  void Update () {
  
      if(beenHit)
      {
          hitTimer -=Time.deltaTime;
  
          if(hitTimer&lt;0)
          {
              beenHit = false;
              RestoreHealth();
          }
      }
  
  }
  </code></pre>