Smooth crouching with the code I have

My script is to make the player crouch slide when press c but the transition to crouch is not smooth.

What I need help with is smoothing out the localScale with the code I have since it snaps to crouching and back standing.

Here is the code:

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

public class CopyPlayerSliding : MonoBehaviour {
    [Header("References")]

    public Transform orientation;
    public Transform playerObj;
    private Rigidbody rb;
    private PlayerMovement pm;


    [Header("Cooldown")]
    [SerializeField] public float CooldownTime = 3f;
    private bool justSlide = false;
    private bool SlideForcedStopped = false;

    [Header("Sliding")]
    [SerializeField] public float maxSlideTime;
    [SerializeField] public float slideForce;
    [SerializeField] private float slideTimer;
    [SerializeField] float slideSetSpeed = 11;
    [SerializeField] float scaleSpeed = 11;
    public float slideYScale;
    private float startYScale;


    private bool CanSlide = false;
    public bool sliding = false;


    [Header("Input")]
    [SerializeField] public KeyCode slideKey = KeyCode.C;
    [SerializeField] KeyCode stopKey = KeyCode.Space;
    private float horizontalInput;
    private float verticalInput;


    private void Start() {
        rb = GetComponent<Rigidbody>();
        pm = GetComponent<PlayerMovement>();

        startYScale = playerObj.localScale.y;
    }

   

    private void Update() {

        verticalInput = Mathf.Clamp(Input.GetAxis("Vertical"), 0f, Mathf.Infinity);

       

        if (Input.GetKeyDown(slideKey) && pm.isGrounded && CanSlide && !justSlide && (horizontalInput != 0 || verticalInput != 0)) {
            StartSlide();
            SlideForcedStopped = false;
        }

        if (Input.GetKey(stopKey) && sliding) {
            ForceStopSlide();
            SlideForcedStopped = true;
        }

    }

    private void FixedUpdate() {
        if (sliding)
            SlidingMovement();

        if (rb.velocity.magnitude > slideSetSpeed) {
            CanSlide = true;
        }
        if (rb.velocity.magnitude < slideSetSpeed) {
            CanSlide = false;

        }

    }

    private void StartSlide() {

        sliding = true;
      

      
        playerObj.localScale = new Vector3(playerObj.localScale.x, slideYScale , playerObj.localScale.z);
       

        rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);

        slideTimer = maxSlideTime;
        if (SlideForcedStopped == false)
            StartCoolDown();
    }

    public void StartCoolDown() {
        StartCoroutine(Cooldown());
        
    }



    private void SlidingMovement() {
        Vector3 inputDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

        // sliding normal
        if (!pm.OnSlope() || rb.velocity.y > -0.1f) {
            rb.AddForce(inputDirection.normalized * slideForce, ForceMode.Force);

            slideTimer -= Time.deltaTime;
        }

        // sliding down a slope
        else {
            rb.AddForce(pm.GetSlopeMoveDirection(inputDirection) * slideForce, ForceMode.Force);
        }

        if (slideTimer <= 0)
            StopSlide();
    }
    private void StopSlide() {
        sliding = false;

        playerObj.localScale = new Vector3(playerObj.localScale.x, startYScale , playerObj.localScale.z);

    }


   

    private void ForceStopSlide() {
        sliding = false;
        


        playerObj.localScale = new Vector3(playerObj.localScale.x, startYScale , playerObj.localScale.z);
        
        rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
        rb.AddForce(transform.up * pm.jumpForce, ForceMode.Impulse);
      

    }


    private IEnumerator Cooldown() {
        justSlide = true;
        
        yield return new WaitForSeconds(CooldownTime);

        justSlide = false;
    }





}

You can gradually change a Vector3 by using Lerp, MoveTowards, or SmoothDamp

Vector3 targetScale = new Vector3 (playerObj.localScale.x, slideYScale, playerObj.localScale.z);
var smoothedScale = Vector3.MoveTowards (playerObj.localScale, targetScale, scaleSpeed * Time.deltaTime);
playerObj.localScale = smoothedScale;