Freeze gameobject rotations in only 2 axes

Hello everyone!

I have a problem for quite a while now. I’m working with google cardboard and i’m trying to do an icon to change the viewmode from mono to stereo and vice versa when we look at it. The icon, which is under the player, needs to follow the player’s moves in x & z and rotations, only in y.

How can I manage to do this?

I tried to make the icon a child of the player gameobject and freeze rotations with script but nothing worked.

Maybe attached to the icon, where targetTransform is the player, the icon will copy the x&z position of the target and the y rotation only:

public Transform targetTransform;

void Update(){
transform.position = new Vector3(targetTransform.position.x, transform.position.y, targetTransform.position.z);
transform.eulerAngles = new Vector3(transform.eulerAngles.x ,targetTransform.eulerAngles.y, transform.eulerAngles.z);
}