Exemplo n.º 1
0
        private void MoveX(PlayerStateMachine stateMachine, CharacterMovementController playerController, float accelerationTime, float moveFactor)
        {
            float directionX = Input.GetAxisRaw("Horizontal");

            stateMachine.FlipSprite(directionX);
            playerController.OnMoving(directionX, accelerationTime, moveFactor);
        }
        public override AbstractState HandleUpdate(PlayerStateMachine stateMachine, Animator animator, CharacterMovementController playerController)
        {
            if (!playerController.IsJumpingPossible())
            {
                return(PlayerStateMachine.idleState);
            }

            if (Input.GetKeyUp(KeyCode.Space))
            {
                float jumpTime         = Time.time - jumpTimerStart;
                float jumpForcePercent = CalculatePercentFromJumpTimer(jumpTime);

                if (jumpForcePercent > 0)
                {
                    // JUMP NOW!

                    stateMachine.InstantiateEffect(dustEffect);
                    playerController.OnJumping(jumpForcePercent);

                    float directionX = Input.GetAxisRaw("Horizontal");
                    if (directionX != 0)
                    {
                        // Spieler will sich beim springen bewegen
                        stateMachine.FlipSprite(directionX);
                        PlayerStateMachine.jumpStartRunningState.InitParameters(directionX);
                        return(PlayerStateMachine.jumpStartRunningState);
                    }
                    else
                    {
                        return(PlayerStateMachine.jumpStartIdleState);
                    }
                }
                else
                {
                    Debug.LogError("Error in PreJumpIdleState: JumpForce <= 0, also kein Sprung möglich!");
                    return(PlayerStateMachine.idleState);
                }
            }
            else
            {
                if (!Input.GetKey(KeyCode.Space))
                {
                    Debug.LogError("Error in PreJumpIdleState: Space Taste nicht mehr gedrückt, aber kein KeyUp!");
                    return(PlayerStateMachine.idleState);
                }
            }

            return(null);
        }