Synchronising the rotation around Y axis of two objects

Hey all,

I have a player and a 3rd person view camera which is controllable by the mouse.
I now want to be able to set the rotation of the player around the Y axis equal to the rotation of the camera around the Y axis.
I tried gameObject.transform.rotation.y = GameObject.Find("Main Camera").transform.rotation.y;. This makes it almost behave as I want it except it only works for 180 degrees. The other 180 degrees the character turns around in the opposite direction.

Does anyone know how I can do this?

Try this:

float camY = Camera.mainCamera.transform.eulerAngles.y;

transform.eulerAngles = new Vector3(transform.eulerAngles.x,camY, transform.eulerAngles.z);