private void AttackTarget() { if (Time.time - lastHitTime > currentWeaponConfig.GetMinTimeBetweenHits()) { SetAttackAnimation(); animator.SetTrigger(ATTACK_TRIGGER); lastHitTime = Time.time; } }
IEnumerator AttackTargetRepeatedly() { bool attackStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (attackStillAlive && targetStillAlive) { float weaponHitPeriod = currentWeaponConfig.GetMinTimeBetweenHits(); float timeToWait = weaponHitPeriod * character.GetAnimSpeedMultiplier(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }
IEnumerator AttackTargetRepeatedly() { // determine if alive (attacker and defender) bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (attackerStillAlive && targetStillAlive) { var animationClip = currentWeaponConfig.GetAttackAnimClip(); float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetMinTimeBetweenHits(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }
IEnumerator AttackTargetRepeatedly() { Debug.Log("Starting repeated attacks"); // determine if still alive (attacker and defender) bool isAttackerAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool isTargetAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (isAttackerAlive && isTargetAlive) { float weaponHitPeriod = currentWeaponConfig.GetMinTimeBetweenHits(); float timeToWait = weaponHitPeriod * character.getAnimSpeedMultiplier; bool isTimeToHitAgain = Time.time - lastTimeHit > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastTimeHit = Time.time; } yield return(new WaitForSeconds(timeToWait)); } // know how often to attack // if time to hit agin // hit target }