Setting a rotation with only one axis.

I’m having trouble at the moment trying to find a way to get the player’s rotation to copy the camera’s rotation, then set it’s X and Z rotations back to 0 so the player still points in the right direction, but doesn’t rotate up or down. I can make the player copy the rotation, but setting x and z back to 0 is also messing with the Y. Instead the Y is in decimal places and only changing by a max of about 1 to -1.
Here is the code:

    //Set the direction player is facing based on mouse
    direction = CalculateDirection(currentX, currentY);

    //Send rotation and position to camera so the camera can calculate the camera position.
    cameraRotation = camera.SetCamera(direction, transform.position); 
    Quaternion pastRot = transform.rotation;
    transform.rotation = cameraRotation; //Copy the rotation. this works.
   
    //Find out where the player is aiming
    bool hit = Physics.Raycast(transform.position, Vector3.forward, out hitpoint, 1000f);
    if (hit == true)
    {
        camera.CameraLook(hitpoint.point);
    }

    transform.rotation = Quaternion.Euler(0, transform.rotation.y, 0); //Y is only changing in small amounts. I tried multiplying by 180 to make up for it but that made it go all over the place.

I’m Still trying to wrap my head around Quaternions, so I may be forgetting something. if someone has a fix, or a easier and/or better solution, I would gladly accept it. Thanks in advance.

Never mind. I fixed it by setting variable and changing the axis’s in advance. still not sure why it was only changing in small amounts before though…