Rotating object in script not working as intended.

I have a car game and I am trying to make the steering wheel rotate only on one axis. Here is what I tried:

    private void RotateWheelVisual()
        carWheelTransform = carWheel.transform;
        carWheelSteerAngle = (maxSteerAngle / 2) * -horizontalInput;
        Quaternion rot = Quaternion.Euler(0, 0, carWheelSteerAngle);
        carWheelTransform.rotation = Quaternion.Lerp(carWheelTransform.rotation, rot, 1);


The problem is the wheel rotates on other axis as the car moves and I do not want that.
What should I do so that the wheel updates itself correctly with the whole car?

I think it’s happening because you are setting x and y angles to 0, not to current rotation of the car wheel, try changes the 5 line to this:

Quaternion rot = Quaternion.Euler(carWheelTransform.eulerAngles.x,  carWheelTransform.eulerAngles.y, carWheelSteerAngle);

Or maybe you are trying to set the local rotation? You can do it with:

carWheelTransform.localRotation= Quaternion.Lerp(carWheelTransform.localRotation, rot, 1);