IEnumerator AttackTargetRepeatedly() { bool isAttackerAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool isTargetAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (isAttackerAlive && isTargetAlive) { var animationClip = currentWeaponConfig.GetAttackAnimation(); float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetMinTimeBetweenAnimationCycles(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait || lastHitTime == -1; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(0.1f)); } }
IEnumerator AttackTargetRepeatedly() { bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (attackerStillAlive && targetStillAlive) { float animationClipTime = currentWeaponConfig.GetDeathAnimationClip().length; animationClipTime /= character.GetAnimationSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetMinTimeBetweenAnimationCycles() + Random.Range(-Constants.ATTACK_TIME_OFFSET, Constants.ATTACK_TIME_OFFSET); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }
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(); //if time to hit again bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }