Beispiel #1
0
    private void TryAttack(AttackType _attack, AttackButton _btn)
    {
        Debug.Log(string.Format("ATTACK: {0}", _attack));
        if (_attack == AttackType.Back && Base.Back_Damage == 0f && isGrounded)
        {
            _attack = AttackType.Projectile;
        }
        if (STATS.Get_Current_Action() == Movement_Direction.Crouching)
        {
            _attack = AttackType.Crouch;
        }

        isAttacking = true;
        float   _cd     = STATS.Get_Attack_CoolDown(_attack, _btn, Base);
        float   _damage = STATS.Get_Attack_Damage(_attack, _btn, Base);
        Vector2 _range  = STATS.Get_Attack_Range(_attack, _btn, Base);

        if (_attack == AttackType.Projectile)
        {
            var CoolDownTimer = StartCoroutine(AnimateAttack(_cd, _btn));
            var co            = StartCoroutine(FireProjectile(_attack, _btn, _cd / 3));
        }
        else if (_attack == AttackType.Forward && _btn == AttackButton.Primary)
        {
            var co = StartCoroutine(FireLongAttack());
        }
        else
        {
            var          CoolDownTimer = StartCoroutine(AnimateAttack(_cd, _btn));
            Collider2D[] enemyInRange  = Physics2D.OverlapBoxAll(attackPos.position, _range, 0, MasterController.Controller.GameSettings.EnemyMask);
            for (int i = 0; i < enemyInRange.Length; ++i)
            {
                if (enemyInRange[i] != this.GetComponent <Collider2D>())
                {
                    var enemy = enemyInRange[i];
                    if (enemy.gameObject.name == "Rectangle")
                    {
                        Destroy(enemy.gameObject);
                    }
                    if (enemy != null)
                    {
                        enemy.GetComponent <Fighter>().TakeDamage(_damage, _attack, _btn);
                    }
                }
            }
        }
    }