IEnumerator Attack() { if (timeBetweenAttacks <= 0) { if (Input.GetKey(KeyCode.Space)) { playerAnimation.SetBool("isAttacking", true); while (playerAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f) { yield return(null); } playerAnimation.SetBool("isAttacking", false); Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies); for (int i = 0; i < enemiesToDamage.Length; i++) { player.InflictDamage(enemiesToDamage[i].GetComponent <EnemyUnit>(), player.Strength); } } timeBetweenAttacks = startTimeBetweenAttacks; } else { timeBetweenAttacks -= Time.deltaTime; } }