Ejemplo n.º 1
0
 private void AttackTarget()
 {
     if (Time.time - lastHitTime > currentWeaponConfig.GetMinTimeBetweenHits())
     {
         SetAttackAnimation();
         animator.SetTrigger(ATTACK_TRIGGER);
         lastHitTime = Time.time;
     }
 }
        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));
            }
        }
Ejemplo n.º 3
0
        IEnumerator AttackTargetRepeatedly()
        {
            // determine if alive (attacker and defender)
            bool attackerStillAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;
            bool targetStillAlive   = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;

            while (attackerStillAlive && targetStillAlive)
            {
                var   animationClip     = currentWeaponConfig.GetAttackAnimClip();
                float animationClipTime = animationClip.length / character.GetAnimSpeedMultiplier();
                float timeToWait        = animationClipTime + currentWeaponConfig.GetMinTimeBetweenHits();

                bool isTimeToHitAgain = Time.time - lastHitTime > timeToWait;

                if (isTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastHitTime = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
        }
Ejemplo n.º 4
0
        IEnumerator AttackTargetRepeatedly()
        {
            Debug.Log("Starting repeated attacks");

            // determine if still alive (attacker and defender)
            bool isAttackerAlive = GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;
            bool isTargetAlive   = target.GetComponent <HealthSystem>().healthAsPercentage >= Mathf.Epsilon;

            while (isAttackerAlive && isTargetAlive)
            {
                float weaponHitPeriod  = currentWeaponConfig.GetMinTimeBetweenHits();
                float timeToWait       = weaponHitPeriod * character.getAnimSpeedMultiplier;
                bool  isTimeToHitAgain = Time.time - lastTimeHit > timeToWait;
                if (isTimeToHitAgain)
                {
                    AttackTargetOnce();
                    lastTimeHit = Time.time;
                }
                yield return(new WaitForSeconds(timeToWait));
            }
            // know how often to attack
            // if time to hit agin
            // hit target
        }