Beispiel #1
0
    /// <summary>
    /// Handle player input
    /// </summary>
    private void HandleInput()
    {
        // Check if player pressed Exit button
        restart.HandleRestart();

        // Check if the player pressed the Exit button
        HandleExit();

        // Get player input (horizontal)
        horizontalInput = Input.GetAxis("Horizontal");
        if (Mathf.Abs(horizontalInput) > 0f)
        {
            currentState.direction    = GetDirection(horizontalInput) ?? previousState.direction;
            currentState.oppDirection = GetDirection(-1 * horizontalInput) ?? previousState.oppDirection;
        }
        else if (Mathf.Abs(pBody.velocity.x) > 1f)
        {
            currentState.direction    = GetDirection(pBody.velocity.x) ?? previousState.direction;
            currentState.oppDirection = GetDirection(-1 * pBody.velocity.x) ?? previousState.oppDirection;
        }
        else
        {
            currentState.direction    = previousState.direction;
            currentState.oppDirection = previousState.oppDirection;
        }

        // Grab object
        grabbing = Input.GetButton("Grab");

        // Checks jump key
        JumpDown();

        // Update equipped material based on input
        HandleMaterial();
    }