Exemplo n.º 1
0
 private void StopRecoiling()
 {
     isRecoiling = false;
     playerAnimator.state.action    = ActionState.stand;
     playerAnimator.state.direction = DirectionState.down;
     lastInputState = playerAnimator.state;
 }
Exemplo n.º 2
0
    void Update()
    {
        if (isRecoiling)
        {
            playerAnimator.state.action = ActionState.death;
        }
        else if (canCharge && isChargePresssed())
        {
            playerAnimator.state.action = ActionState.fix;
            if (closestTower.transform.position.x < this.transform.position.x)
            {
                playerAnimator.state.direction = DirectionState.left;
            }
            else
            {
                playerAnimator.state.direction = DirectionState.right;
            }
            isCharging = true;
        }
        else
        {
            if (isCharging)
            {
                playerAnimator.state.action    = ActionState.stand;
                playerAnimator.state.direction = DirectionState.down;
            }

            isCharging = false;
            // Save last pressed key to prioritize the last pressed key
#if MOBILE_INPUT
            float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
            float vertical   = CrossPlatformInputManager.GetAxis("Vertical");
            if (Mathf.Abs(horizontal) >= float.Epsilon && Mathf.Abs(horizontal) > Mathf.Abs(vertical))
            {
                playerAnimator.state.action = ActionState.walk;
                if (horizontal > float.Epsilon)
                {
                    //right
                    playerAnimator.state.direction = DirectionState.right;
                }
                else if (horizontal <= float.Epsilon)
                {
                    //left
                    playerAnimator.state.direction = DirectionState.left;
                }
            }
            else if (Mathf.Abs(vertical) >= float.Epsilon && Mathf.Abs(vertical) >= Mathf.Abs(horizontal))
            {
                playerAnimator.state.action = ActionState.walk;
                if (vertical > float.Epsilon)
                {
                    //up
                    playerAnimator.state.direction = DirectionState.up;
                }
                else if (vertical <= float.Epsilon)
                {
                    //down
                    playerAnimator.state.direction = DirectionState.down;
                }
            }
            else
            {
                //none
                playerAnimator.state.action = ActionState.stand;
            }
#else
            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
            {
                lastInputState = new PlayerAnimator.PlayerMoveState(ActionState.walk, DirectionState.up);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
            {
                lastInputState = new PlayerAnimator.PlayerMoveState(ActionState.walk, DirectionState.down);
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
            {
                lastInputState = new PlayerAnimator.PlayerMoveState(ActionState.walk, DirectionState.left);
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
            {
                lastInputState = new PlayerAnimator.PlayerMoveState(ActionState.walk, DirectionState.right);
            }

            if (lastInputState == PlayerAnimator.PlayerMoveState.walkUp && isUpPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkUp;
            }
            else if (lastInputState == PlayerAnimator.PlayerMoveState.walkDown && isDownPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkDown;
            }
            else if (lastInputState == PlayerAnimator.PlayerMoveState.walkLeft && isLeftPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkLeft;
            }
            else if (lastInputState == PlayerAnimator.PlayerMoveState.walkRight && isRightPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkRight;
            }
            else if (isUpPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkUp;
            }
            else if (isDownPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkDown;
            }
            else if (isLeftPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkLeft;
            }
            else if (isRightPressed())
            {
                playerAnimator.state = PlayerAnimator.PlayerMoveState.walkRight;
            }
            else
            {
                if (playerAnimator.state.action == ActionState.walk)
                {
                    //Didn't move but is in walking animation
                    playerAnimator.state.action = ActionState.stand;
                }
            }
#endif
        }
        lastInputState = playerAnimator.state;
    }