IEnumerator AttackTargetRepeatedly() { bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon; while (attackerStillAlive && targetStillAlive) { //float weaponHitRate = currentWeaponConfig.GetTimeBetweenAnimationCycles(); //float timeToWait = weaponHitRate * character.GetAnimSpeedMultiplier(); var animationClip = currentWeaponConfig.GetAttackAnimClip(); float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetTimeBetweenAnimationCycles(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }
private void SetAttackAnimation() { if (!character.GetOverrideController()) { Debug.Break(); Debug.LogAssertion("Please Provide " + gameObject + "with a animator override controller"); } else { var animatorOverrideController = character.GetOverrideController(); animator.runtimeAnimatorController = animatorOverrideController; animatorOverrideController[DEFAULT_ATTACK] = currentWeaponConfig.GetAttackAnimClip(); animatorOverrideController[IDLE] = currentWeaponConfig.GetIdleWeaponClip(); } }
public override float GetAttackRate() { if (myRPGWeapon != null) { var animationClip = myRPGWeapon.GetAttackAnimClip(); float animationClipTime = animationClip.length / myAnimator.speed;/*character.GetAnimSpeedMultiplier()*/ float _timeToWait = animationClipTime + myRPGWeapon.GetTimeBetweenAnimationCycles(); return(_timeToWait); } else { return(0.25f); } }
//public void AttackTarget(GameObject targetToAttack) //{ // StartCoroutine(AttackTargetRepeatedly()); //} //public void StopAttacking() //{ // animator.StopPlayback(); // StopAllCoroutines(); //} IEnumerator AttackTargetRepeatedly(Transform target) { // determine if alive (attacker and defender) var _targetAlly = target.GetComponent <AllyMemberRPG>(); while (allymember != null && allymember.IsAlive && _targetAlly != null && _targetAlly.IsAlive) { var animationClip = currentWeaponConfig.GetAttackAnimClip(); float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier(); float timeToWait = animationClipTime + currentWeaponConfig.GetTimeBetweenAnimationCycles(); bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait; if (isTimeToHitAgain) { AttackTargetOnce(target); lastHitTime = Time.time; } yield return(new WaitForSeconds(timeToWait)); } }