Auto crouching problem

@AndreM1 Hi, my character for some reason auto crouches when he he walks up to a wall, goes under an object and if i spam the jump button on a wall, he would climb up it. I also added a crouch animation and i followed @AT-Brackeys tutorials on player movement and player animation 2D (Did not do jump animation) I used Visual studio C#. Someone please help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {

    public CharacterController2D controller;
    public Animator animator;

    public float runSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;

    // Update is called once per frame
    void Update() {

        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

            jump = true;

        if (Input.GetButtonDown("Crouch"))
            crouch = true;
        } else if (Input.GetButtonUp("Crouch"))
            crouch = false;


    public void OnCrouching (bool isCrouching)
        animator.SetBool("IsCrouching", isCrouching);

    void FixedUpdate ()
        //Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;

I’m not sure if this is correct, but I would use animator.Play("IsCrouching") and check to see if that was true in line 40.

Ok i will try that thanks! @AndreM1 please help.

what for you using this ?

public void OnCrouching (bool isCrouching)

you haven’t calling this any where.