IEnumerator AttackTargetRepeatedlyRoutine(GameObject targetToAttack) { bool isTargetStillAlive = targetToAttack.GetComponent <HealthSystem>().GetCurrentHealthPoints() > 0; bool isAttackerStillAlive = GetComponent <HealthSystem>().GetCurrentHealthPoints() > 0; while (isTargetStillAlive == true && isAttackerStillAlive == true) { bool isItTimeToHit = attackCooldown <= 0; if (isItTimeToHit == true) { AttackTargetForEnemy(targetToAttack); attackCooldown = currentWeaponInUse.GetWeaponAttackSpeed(); } yield return(new WaitForSeconds(attackCooldown)); } }