// Start is called before the first frame update
 void Start()
 {
     state         = PlayerCharacter.VelocityState.idle;
     Camera        = GameObject.Find("2DCamera(Clone)");
     VirtualCamera = Camera.GetComponent <CinemachineVirtualCamera>();
     fComposer     = VirtualCamera.GetCinemachineComponent <CinemachineFramingTransposer>();
 }
    // UpdateAnimationState updates the velocity state which allows or disallows
    // certian actions to be preformed by the player.
    private void UpdateAnimationState()
    {
        switch (state)
        {
        case PlayerCharacter.VelocityState.idle:
            if (Mathf.Abs(rb.velocity.x) > 0)
            {
                state = PlayerCharacter.VelocityState.walking;
            }
            break;

        case PlayerCharacter.VelocityState.walking:
            if (Mathf.Abs(rb.velocity.x) < .1f)
            {
                state = PlayerCharacter.VelocityState.idle;
            }
            break;

        case PlayerCharacter.VelocityState.jumping:
            if (rb.velocity.y < 0.1f)
            {
                state = PlayerCharacter.VelocityState.falling;
            }
            break;

        case PlayerCharacter.VelocityState.falling:
            if (capsuleCollider2d.IsTouchingLayers(groundMask))
            {
                state = PlayerCharacter.VelocityState.idle;
            }
            break;

        case PlayerCharacter.VelocityState.hurt:
            if (Mathf.Abs(rb.velocity.x) < .1f)
            {
                state = PlayerCharacter.VelocityState.idle;
            }
            break;

        case PlayerCharacter.VelocityState.crouch:
            if (Input.GetButtonUp("Crouch"))
            {
                state = PlayerCharacter.VelocityState.crouch;
            }
            break;

        default:
            state = PlayerCharacter.VelocityState.idle;
            break;
        }
    }
    /**
     *  If the player is allowed to crouch at a given time, the camera will move downwards in the y direction
     *  so that the player can peek below them and see if there is a place for them to jump down to safely.
     *  @param crouching (bool) - determines if the camera should move up or down when crouching or standing up.
     */
    private void toggleCrouch(bool crouching)
    {
        if (crouching)
        {
            state = PlayerCharacter.VelocityState.crouch; // Used for animation state changes

            fComposer           = VirtualCamera.GetCinemachineComponent <CinemachineFramingTransposer>();
            fComposer.m_ScreenY = 0.0f;
        }

        else
        {
            state               = PlayerCharacter.VelocityState.idle; // Used for animation state changes
            fComposer           = VirtualCamera.GetCinemachineComponent <CinemachineFramingTransposer>();
            fComposer.m_ScreenY = 0.5f;
        }
    }
    // Update is called a fixed amount per second
    void Update()
    {
        if (canEndLevel)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }

        // Allow movement if the player is not recovering from damage.
        if (state != PlayerCharacter.VelocityState.hurt)
        {
            Movement();
        }

        UpdateAnimationState();

        if (Input.GetButtonDown("Fire1") && state != PlayerCharacter.VelocityState.crouch)
        {
            state = PlayerCharacter.VelocityState.attacking;
        }

        if (Input.GetButtonDown("Crouch") && state == PlayerCharacter.VelocityState.idle)
        {
            toggleCrouch(true);
        }

        else if (Input.GetButtonUp("Crouch"))
        {
            toggleCrouch(false);
        }

        if (Input.GetButtonDown("PlaceLadder"))
        {
            Debug.Log("Get the room that the player is \"in\"");
        }

        anim.SetInteger("state", (int)state);
    }
 // Allows the player to jump.
 public void Jump()
 {
     rb.velocity = new Vector2(rb.velocity.x, jumpForce);
     state       = PlayerCharacter.VelocityState.jumping;
 }
 /**
  *  Used by an animator component to update the players animations
  *  @param state (VelocityState) - the new velocity state.
  */
 public void updateState(PlayerCharacter.VelocityState state)
 {
     this.state = state;
 }