Example #1
0
        private IEnumerator AttackTargetRepeatedly()
        {
            bool attackerStillAlive = GetComponent <HealthSystem>().HealthAsPercentage() >= Mathf.Epsilon;
            bool targetStillAlive   = target.GetComponent <HealthSystem>().HealthAsPercentage() >= Mathf.Epsilon;

            while (attackerStillAlive && targetStillAlive)
            {
                AnimationClip animationClip     = currentWeaponConfig.GetAttackAnimClip();
                float         animationClipTime = animationClip.length / character.GetAnimationSpeedMultiplier();
                float         attackTime        = animationClipTime + currentWeaponConfig.GetWaitTimeBetweenAnimations();

                bool timeToAttack = (Time.time - lastHitTime) > attackTime;

                if (timeToAttack)
                {
                    lastHitTime = Time.time;

                    AttackTargetOnce();
                }

                yield return(new WaitForSeconds(attackTime));
            }
        }