Example #1
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();
                float timeToWait = currentWeaponConfig.GetTimeToWaitBetweenHits();
                //if time to hit again
                bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait;

                if (isTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastHitTime = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
        }
Example #2
0
        private void SetAttackAnimation()
        {
            if (!character.GetAnimatorOverrideController())
            {
                Debug.LogAssertion("Please provide " + gameObject.name + "with an animator override controller.");
                Debug.Break();
            }
            animator = GetComponent <Animator>();
            var animatorOverrideController = character.GetAnimatorOverrideController();

            animator.runtimeAnimatorController         = animatorOverrideController;
            animatorOverrideController[DEFAULT_ATTACK] = currentWeaponConfig.GetAnimClip();
        }
Example #3
0
        IEnumerator AttackTargetRepeatadly()
        {
            bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;
            bool targetStillAlive   = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;

            while (attackerStillAlive && targetStillAlive)
            {
                var   animationClip     = currentWeaponConfig.GetAnimClip();
                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));
            }
        }