Lock transform rotation on Y axis

Hello,

I have a script where you can climb up walls and ceilings with a guy 2D.

But sometimes he deviates off the course.

How can i lock his rotation? The scripts is pretty complicated.

private Quaternion GetMagneticRotation()
{
    closestSphereCastHit = null;

    if (Physics.SphereCast(transform.position, collider.radius, -transform.up + transform.forward, out RaycastHit hitForward, SPHERECAST_DISTANCE, RayCastLayerMask))
        closestSphereCastHit = hitForward;

    if (Physics.SphereCast(transform.position, collider.radius, -transform.up, out RaycastHit hitDown, SPHERECAST_DISTANCE, RayCastLayerMask))
    {
        if (!closestSphereCastHit.HasValue || closestSphereCastHit.Value.distance > hitDown.distance)
            closestSphereCastHit = hitDown;
    }

    if (Physics.SphereCast(transform.position, collider.radius, -transform.up - transform.forward, out RaycastHit hitBack, SPHERECAST_DISTANCE, RayCastLayerMask))
    {
        if (!closestSphereCastHit.HasValue || closestSphereCastHit.Value.distance > hitBack.distance)
            closestSphereCastHit = hitBack;
    }

    var normal = closestSphereCastHit?.normal ?? Vector3.zero;

    var lookRot = Quaternion.LookRotation(Vector3.Cross(transform.right, normal), normal);
    return lookRot;
}

private void MagneticRotate()
{
    var stickedRotation = GetMagneticRotation();

    if (Time.time > lastTimeWooshed + 0.5f && stickedRotation != lastStickedRotation && Time.time > 1f)
    {
        WooshSound.Play();
        lastTimeWooshed = Time.time;
    }

    var desRot = Quaternion.Slerp(transform.rotation, stickedRotation, Time.fixedDeltaTime * currentMagneticRotationSpeed);
    transform.rotation = desRot;

    //transform.Rotate(new Vector3(0f, 1f, 0f), 1f);

    lastStickedRotation = stickedRotation;
}

trasform.rotation = desRot;
////////////
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, 0, transform.localEulerAngles.z);