Example #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));
            }
        }
Example #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));
            }
        }
Example #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;
            }
        }
Example #4
0
        IEnumerator AttackTargetRepeatedly()
        {
            while (character.StillAlive() && currentTarget.GetComponent <Character>().StillAlive())
            {
                var   animClip     = weaponInUse.GetAttackAnimClip();
                float animClipTime = animClip.length / character.GetAnimSpeedMultiplier();
                float timeToWait   = animClipTime + weaponInUse.AttackCooldown();

                bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait;
                if (isTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastHitTime = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
        }
        IEnumerator AttackTargetRepeatedly()
        {
            bool attackStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;
            bool targetStillAlive = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;

            while (attackStillAlive && targetStillAlive)
            {
                float weaponHitPeriod  = currentWeaponConfig.GetMinTimeBetweenHits();
                float timeToWait       = weaponHitPeriod * character.GetAnimSpeedMultiplier();
                bool  isTimeToHitAgain = Time.time - lastHitTime > timeToWait;
                if (isTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastHitTime = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
        }
Example #6
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));
            }
        }