Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        IEnumerator AttackTargetRepeatedly()
        {
            // determine if alive (attacker and defender)
            bool attackerStillAlive = GetComponent <HealthSystem>().HealthAsPercentage >= Mathf.Epsilon;
            bool defenderStillAlive = target.GetComponent <HealthSystem>().HealthAsPercentage >= Mathf.Epsilon;

            // while the attacker and the defender still alive keep attacking ???
            // tneho que testar se o atacante ainda esta vivo, se esta continua atacando
            while (attackerStillAlive && defenderStillAlive)
            {
                var animationClip = currentWeaponConfig.GetAttackAnimationClip();

                // is the multiplier is 2 it will be twice as fast, them the clip time will be half as long
                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));
            }
        }
Exemplo n.º 3
0
        public void AttackTargets(Collider[] targets)
        {
            foreach (var target in targets)
            {
                this.target = target.gameObject;
            }

            var   animationClip     = currentWeaponConfig.GetRandomAttackAnimClip();
            float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier();
            float timeToWait        = animationClipTime + currentWeaponConfig.GetTimeBetweenAnimationCycles();

            bool isTimeToHitAgain = (Time.time - lastHitTime) > timeToWait;

            if (isTimeToHitAgain)
            {
                SetAttackAnimation();
                animator.SetTrigger(ATTACK_TRIGGER);
                lastHitTime = Time.time;
            }
        }