How to make a gameObject's Y rotation being another gameObjects' X rotation

so i have an object and a camera and when the camera rotates up and down the x rotation is modified but when my object rotates up and down the y rotation is modified… whatever… I want my gameObject’s y rotation being = to the camera’s x rotation can you help me ?
i searched many forums and posts and i didnt get it can you help me ?
c#

var cameraXRot = camera.rotation.eulerAngles.x;
var charactersEulerRot = character.rotation.eulerAngles;
character.rotation = Quaternion.Euler(charactersEulerRot.x, cameraXRot, characterEulerRot.z);

You might run into strange results if you’re changing the x and z rotation of your character as well because Quaternions behave a little differently than x/y/z rotations (Euler), but this should work in most cases.