IEnumerator AttackTargetRepeatedly() { //determine if alive (Attacker or defender) bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; //while still alive while (attackerStillAlive && targetStillAlive) { //know how often to attack var animationClip = currentWeaponConfig.GetAnimClip(); float animationClipTime = animationClip.length / character.GetAnimatorSpeedMultiplier(); //float timeToWait = animationClipTime + currentWeaponConfig.GetMinTimeBetweenAnimationCycles(); float timeToWait = currentWeaponConfig.GetTimeToWaitBetweenHits(); //if time to hit again bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }
private IEnumerator AttackRepeatidly() { while (GetComponent <HealthSystem>().GetIsAlive() == true && currentTarget.GetIsAlive()) { float hitPeriod = characterStats.GetActionSpeed(); float waitTime = hitPeriod * character.GetAnimatorSpeedMultiplier(); bool hitAgain = Time.time - lastHitTime > waitTime; if (hitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(waitTime)); } }