IEnumerator AttackTargetRepeatedly() { bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (attackerStillAlive && targetStillAlive) { var animationClip = currentWeaponConfig.GetAnimClip(); float animationClipTime = animationClip.length / character.GetAnimationSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetTimeBetweenAnimationsCycle(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }