コード例 #1
0
ファイル: Fighter.cs プロジェクト: bgrillsdesigns/Masters
    // Update is called once per frame
    void Update()
    {
        //Stops Attacks
        if (isStunned)
        {
            CancelInvoke();
        }

        //Check if AI
        if (isAI)
        {
            var   distance    = Vector2.Distance(EnemyTransform.position, transform.position);
            float _vertical   = AI_shouldCrouch ? -1f : 0f;
            float _horizontal = AI_shouldAdvance && distance > Base.Secondary_Range_X ? EnemyTransform.position.x > transform.position.x ? 1f : -1f : 0f;
            STATS.Set_Current_Movement(_horizontal, _vertical, Player_Facing_Right,
                                       AI_shouldCrouch, AI_shouldJump, Utils.GetARandomBool(), AI_shouldBlock);
            Collider2D[] enemyInRange = Physics2D.OverlapBoxAll(attackPos.position,
                                                                new Vector2(Base.Secondary_Range_X, Base.Secondary_Range_Y), 0, MasterController.Controller.GameSettings.EnemyMask);
            if (enemyInRange.Length > 1 && !isAttacking && AI_shouldAdvance && !isStunned)
            {
                isAttacking = true;
                StopMoving();
                AttackType   _type = Utils.GetARandomAttack();
                AttackButton _btn  = Utils.GetARandomButton();
                TryAttack(_type, _btn);
            }
        }
        else
        {
            STATS.Set_Current_Movement(Input.GetAxisRaw(Horizontal), Input.GetAxisRaw(Veritical), Player_Facing_Right,
                                       Input.GetAxisRaw(Crouch) > 0, Input.GetButtonDown(Jump), Input.GetButtonDown(Sprint), Input.GetAxisRaw(Block) > 0);

            var movement = STATS.Get_Current_Movement();
            if (Input.GetAxisRaw(PrimaryFire) > 0 && !isAttacking && !isStunned)
            {
                isAttacking = true;
                StopMoving();
                if (movement == Movement_Direction.Forward)
                {
                    TryAttack(AttackType.Forward, AttackButton.Primary);
                }
                else if (movement == Movement_Direction.Backward)
                {
                    TryAttack(AttackType.Back, AttackButton.Primary);
                }
                else if (movement == Movement_Direction.Neutral)
                {
                    TryAttack(AttackType.Neutral, AttackButton.Primary);
                }
            }
            if (Input.GetAxisRaw(SecondaryFire) > 0 && !isAttacking && !isStunned)
            {
                isAttacking = true;
                StopMoving();
                if (movement == Movement_Direction.Forward)
                {
                    TryAttack(AttackType.Forward, AttackButton.Secondary);
                }
                else if (movement == Movement_Direction.Backward)
                {
                    TryAttack(AttackType.Back, AttackButton.Secondary);
                }
                else if (movement == Movement_Direction.Neutral)
                {
                    TryAttack(AttackType.Neutral, AttackButton.Secondary);
                }
            }
        }
        var move = STATS.Get_Current_Action();

        if (move == Movement_Direction.Blocking || move == Movement_Direction.Crouching || move == Movement_Direction.Crouch_Blocking)
        {
            StopMoving();
        }
        playerAnim.SetBool("IsBlocking", move == Movement_Direction.Blocking || move == Movement_Direction.Crouch_Blocking);
        playerAnim.SetBool("IsCrouching", move == Movement_Direction.Crouching || move == Movement_Direction.Crouch_Blocking);
        playerAnim.SetBool("IsGrounded", isGrounded);
    }