title: How to make Physics2D.OverlapBoxAll() Active for x time, and only interact with the new objects it collides with?
body: <p>I have a very simple 2D game where the player is placed on the left, while the enemies are placed on the right and they move towards the player.</p>
  
  <p>The player would attack the enemies with a sword, and I have this current function for it:</p>
  
  <pre class="lang-c# prettyprint-override"><code>[SerializeField] int damage = 1;
  [SerializeField] Transform attackPos;
  [SerializeField] LayerMask whatIsEnemy;
  [SerializeField] float attackRangeX;
  [SerializeField] float attackRangeY;
  
  private void Update()
  {
      if (Input.GetKeyDown(KeyCode.A))
      {
          DamageEnemies();
      }
  }
  
  private void DamageEnemies()
  {
      Collider2D[] enemiesToDamage = Physics2D.OverlapBoxAll(attackPos.position, new Vector2(attackRangeX, attackRangeY), 0, whatIsEnemy);
      for (int i = 0; i &lt; enemiesToDamage.Length; i++)
      {
          enemiesToDamage[i].GetComponent&lt;EnemyController&gt;().TakeDamage(damage);
      }
  }
  </code></pre>
  
  <p>attackPos game object is just placed in front of the player.
  AttackRangeX and Y resemble a square in front of the player.</p>
  
  <p>The problem with this setup is that when the attack key is pressed, it will interact with the enemies inside at that point in time only, which is a single frame.</p>
  
  <p>How can I have the collision active for 5 seconds, but only damage the <strong>new</strong> enemies <strong>once</strong>. I wouldn't want it to keep damaging the enemies it already damaged.</p>