How to make player crouch smoothly, PLZ HELP !!!!

Hi. I have done the code for my player to crouch when I press the C button and stand up when press C again. The problem is my player does this instantly and I dont know to put my crouchingSpeed variable and time.deltatime to my code to make my crouch be smooth. Here’s the code. @dcordoba PLZ HELP !!

public bool isCrouched = false;
public CharacterController controller;
public float crouchDistance = 0.9f;
public float crouchingSpeed = 0.7f;

// Start is called before the first frame update
void Start()
{
    controller = GetComponent<CharacterController>();
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.C))
    {
        if(isCrouched == false)
        {
            isCrouched = true;
            //transform.position = (transform.position + new Vector3(0, -crouchDistance , 0));
            transform.Translate(new Vector3(0, -crouchDistance , 0));
        }
        else if(isCrouched == true)
        {
            isCrouched = false;
            //transform.position = (transform.position + new Vector3(0, crouchDistance , 0));
            transform.Translate(new Vector3(0, crouchDistance, 0));
        }
    }
}

My bad, I rushed the code previously and did not think you’d like to just change the transform Y-Position.
Here is a revised one, done with more effort. Enjoy yourself

 public bool isCrouched = false;
    public CharacterController controller;
    public float crouchDistance = 0.9f;
    public float crouchingSpeed = 0.7f;
    public bool isChangingPosition = false;

    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        //True if Key Pressed and Not changing positions currently
        if (Input.GetKeyDown(KeyCode.C))
            StartCoroutine(Crouch());
    }

    private IEnumerator Crouch()
    {
        //True if we're already changing position, then end this function
        if (isChangingPosition)
            yield break;

        //Acknowledge that we are changing position so above criteria will keep out multiple calls
        isChangingPosition = true;

        //Get our Starting Height
        float StartingHeight = transform.position.y;

        //Find our End Height
        float EndHeight;
        if (isCrouched)
            EndHeight = StartingHeight + crouchDistance; //We are crouched, hence we are trying to stand up (Go Up / Increase)
        else
            EndHeight = StartingHeight - crouchDistance; //We are standing, hence we are trying to crouch (Go Down / Decrease)

        Debug.Log("E" + EndHeight);

        //Keep changing the Y Value until we reach the end height
        while (transform.position.y != EndHeight)
        {
            //Here we check what action we're doing (Standing/Crouching)
            //Then we move according to the action
            //And finally we check if we have reached the End

            if (isCrouched)
            {
                //We are crouched, hence we are trying to stand up (Go Up / Increase)
                transform.Translate(Vector3.up * crouchingSpeed * Time.deltaTime);

                //True if we reached our goal
                if (transform.position.y >= EndHeight)
                {
                    //Make sure we are EXACTLY at the EndHeight
                    transform.position = new Vector3(transform.position.x, EndHeight, transform.position.z);
                    Debug.Log("COMPLETE!");
                }
            }
            else
            {
                //We are standing, hence we are trying to crouch (Go Down / Decrease)
                transform.Translate(Vector3.down * crouchingSpeed * Time.deltaTime);

                //True if we reached our goal
                if (transform.position.y <= EndHeight)
                {
                    //Make sure we are EXACTLY at the EndHeight
                    transform.position = new Vector3(transform.position.x, EndHeight, transform.position.z);
                    Debug.Log("COMPLETE!");
                }
            }
            yield return null;
        }

        //We have reached the end!

        //Flip the Action as we have succeeded in changing now
        isCrouched = !isCrouched;

        //We're finished changing!
        isChangingPosition = false;

        yield return null;
    }

You need to apply a time factor to the translation.
You can use Vector3.Lerp as mentioned in this post:

Maybe you could also make a basic animation for that through the editor and customize there the speed curve of the movement graphically. Also you can then blend animations through the Animator controller’s transitions.