Ejemplo n.º 1
0
        protected override IEnumerator Attack()
        {
            isAttacking = true;
            int   split     = (isoRenderer.possibleDirections == PossibleDirection.Four) ? 4 : 8;
            float startTime = Time.time;
            // fire projectile
            Vector2 attackDirection = (target.position - transform.position).normalized;
            float   angle           = DetermineArrowAngle(attackDirection);
            int     dir             = CharacterRenderer.DirectionToIndex(direction, split);

            isoRenderer.animator.Play(attackAnimations[dir]);
            yield return(new WaitForSeconds(attackDuration / 4));

            GameObject projectile = pooler.RetrieveFromPool(Constants.PoolTags.Arrow, transform.position, new Vector3(45, 0, angle), transform);

            projectile.GetComponent <Projectile>().Initialise(damage, projectileSpeed, attackDirection);
            pooler.ReturnToPool(Constants.PoolTags.Arrow, projectile, 3f);

            float randomDelay = UnityEngine.Random.Range(0, maxAttackDelayRange);

            // render animations
            yield return(new WaitForSeconds(attackCooldown + randomDelay));

            isAttacking = false;
        }
Ejemplo n.º 2
0
        protected override IEnumerator Attack()
        {
            isAttacking       = true;
            isAttackAnimating = true;
            int   split     = (isoRenderer.possibleDirections == PossibleDirection.Four) ? 4 : 8;
            float startTime = Time.time;
            int   dir       = CharacterRenderer.DirectionToIndex(direction, split);

            isoRenderer.animator.Play(attackAnimations[dir]);

            float journey     = 0;
            bool  hasAttacked = false;

            while (journey <= attackDuration)
            {
                journey += Time.deltaTime;
                if (
                    !hasAttacked &&
                    // will allow the player to evade from the attack in tkhe
                    // first half of attack duration
                    journey >= attackDuration / 2 &&
                    Vector2.Distance(transform.position, target.position) <= attackRange
                    )
                {
                    target.GetComponent <Witch>().TakeDamage(damage);
                    hasAttacked = true;
                }
                yield return(null);
            }
            isAttackAnimating = false;
            yield return(new WaitForSeconds(attackCooldown));

            isAttacking = false;
        }
Ejemplo n.º 3
0
        protected override IEnumerator Attack()
        {
            isAttacking = true;
            float   randomDelay     = UnityEngine.Random.Range(0, attackDelayRange);
            int     split           = (isoRenderer.possibleDirections == PossibleDirection.Four) ? 4 : 8;
            Vector2 attackDirection = (target.position - transform.position).normalized;
            int     dir             = CharacterRenderer.DirectionToIndex(direction, split);

            yield return(new WaitForSeconds(randomDelay));

            GameObject spellObj = pooler.RetrieveFromPool(Constants.PoolTags.Spell, GetAttackPosition(), Vector3.zero, transform);

            spellObj.transform.localScale = Vector3.one * attackRadius;
            spellObj.GetComponent <AreaOfAttack>().Initialise(damage, chargeTime, afterEffectTime);
            pooler.ReturnToPool(Constants.PoolTags.Spell, spellObj, 3f);
            // render animations
            isoRenderer.animator.Play(attackAnimations[dir]);
            yield return(new WaitForSeconds(attackCooldown));

            isAttacking = false;
        }