Copy an objects rotation to a camera

Hello,
I’m trying to follow a player with a camera.
I can not just child it to the object due to prefab reasons.

Right now, i have following of the object working, but i want it to rotate with the object as well.

This is the part i’m having trouble with:

void Update (){
this.transform.localEulerAngles = this.transform.localEulerAngles + new Vector3(0,0, player.transform.rotation.y);
}

It grabs the rotation value of the player correctly, but it spins the camera around with that value.
I want it to put the same value in the camera’s rotation instead.

void Update (){

this.transform.localRotation = Quaternion.Euler(new Vector3(0,player.transform.rotation.y,0));

}

Something like this?

this is happening because every frame your adding the players y euler angles to "this"s euler angles. basically say on the first frame your camera has a euler angle z value of 10, and the player has a rotation of on the y 20. the next frame the camera’s z euler angle is 30, and the player is still at 20 y, it will keep doing this every frame so you just constantly spin around… maybe try…

void Update (){
    this.transform.localEulerAngles = new Vector3(this.transform.localEulerAngles.x, this.transform.localEulerAngles.y, player.transform.rotation.y);
}