title: Heal reset Unity C#
body: <p>I implemented healing into my Unity project and have a timer for when the player can heal and I want the timer to reset every time the player takes damage but I can't seem to get it to work.. here is my code:</p>
  <pre><code>private void HealthRegen()
  {
      timer += Time.deltaTime;
     
      if (timer &gt; timeToHeal) 
      {
          StartCoroutine(HealthRegenCo());
      }
      if (damaged == true)
      {
          timer = 0f;
      }
  }
  
  private void SetHealth(float value)
  {
      currentHealth = Mathf.Clamp(value, 0f, 100f);
      healthbar.value = currentHealth;
  }
  
  private IEnumerator HealthRegenCo()
  {
      while (enabled)
      {
         yield return new WaitForSeconds(0.1f);
         SetHealth(currentHealth + healAmount);
         Save();
      }
  }
  </code></pre>