title: How do you remove health of multiple enemies?
body: <pre><code>using System.Collections;
  
  public class TowerAttack : MonoBehaviour {
  
  public float timeBetweenAttacks = 0.5f;
  public int attackDamage = 10;
  
  GameObject player;
  PlayerHealth playerHealth;
  bool playerInRange;
  float timer;
  
  void Awake()
  {
      player = GameObject.FindGameObjectWithTag ("Player");
      playerHealth = player.GetComponent&lt;PlayerHealth&gt; ();
  
  }
  
  void OnTriggerEnter(Collider other)
  {
      print (other);
      if (other.gameObject == player)
          playerInRange = true;
  }
  
  void OnTriggerExit(Collider other)
  {
      if (other.gameObject == player)
          playerInRange = false;
  }
  
  // Update is called once per frame
  void Update () {
  
      timer += Time.deltaTime;
  
      if (timer &gt;= timeBetweenAttacks &amp;&amp; playerInRange)
          Attack ();
      if (playerHealth.currentHealth &lt;= 0)
          print ("Player's dead");
  }
  
  void Attack()
  {
      timer = 0f;
      print (playerHealth);
      if (playerHealth.currentHealth &gt; 0)
          playerHealth.TakeDamage (attackDamage);
  }
  }
  </code></pre>
  
  <p>I am using this code on an object called tower and it has box collider with istrigger active. There are multiple objects spawn on the field with "PlayerHealth" script attached and tagged as "Player". However only the first "Player" which enter the box collider get its health remove and the rest of the "Player" objects stay healthy.</p>