title: Enemy health bar and taking damage
body: <p>I have added the following script to my enemies for the purpose of having a health bar:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class Enemy_Health : MonoBehaviour {
  
      public float health;
      public float maxHealth;
  
      public GameObject healthBarUI;
      public Slider slider;
  
      private void Start()
      {
          health = maxHealth;
          slider.value = calculateHealth();
  
      }
      private void Update()
      {
          slider.value = calculateHealth();
          if (health &lt; maxHealth)
          {
              healthBarUI.SetActive(true);
          }
          if (health &lt;= 0)
          {
              Destroy(gameObject);
          }
          if (health &gt; maxHealth)
          {
              health = maxHealth;
          }
      }
      float calculateHealth()
      {
          return health / maxHealth;
      }
  }
  </code></pre>
  
  <p>It is working well. However, my player has a weapon (axe) and I would like when my player attacks using the weapon, the health bar of the enemy decreases.</p>