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

            while (attackerStillAlive && targetStillAlive)
            {
                var   animationClip     = currentWeponConfig.GetWeponAnimation();
                float animationClipTime = animationClip.length / character.GetAnimationSpeedMultiplyer();
                float timeToWait        = animationClipTime + currentWeponConfig.GetTimeBetweenAnimationCycles();

                bool isItTimeToHitAgain = Time.time - lastHitTime > timeToWait;

                if (isItTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastHitTime = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
        }