Change rotation by script

How to change rotation by script? I want one to object to have Y rotation of second. Only Y, not X and Z. How to do that?

I have this:

movementSphere2.transform.rotation = cameraCharacter.transform.localRotation;

But it just copy whole rotation, i want Y of “cameraCharacter” only.

First, when working with individual axes, using euler angles is far easier than trying to edit the quaternion rotations. Knowing that, it’s just a matter of making a local copy of the euler angles, setting the y of that copy to the desired value, then assigning the local copy back to the transform:

Vector3 angles = movementSphere2.transform.eulerAngles;
angles.y = cameraCharacter.transform.eulerAngles.y;
movementSphere2.transform.eulerAngles = angles;

you should set the rotation via Quaturnian .

movementSphere2.transform.rotation.y = new Quaternion (0, cameraCharacter.transform.localRotation.y, 0,1);

Also I’m not sure i am understanding too clearly .

you want to set the y rotation of movementSphere2 ONLY , correct ?

le me know if i’m incorrect and I will change my answer.