Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }