Rotate object individual quaternion/euler angles from script

Hi all,

I am trying to figure out how i can take an object and assign it individual rotation axis so it mimic’s the rotation of multiple other objects. So obj_0 should have rotation X follow obj_1 and rotation Y follow obj_2, etc.

I don’t understand why this wouldn’t work -

public GameObject cube;
public GameObject anothercube;
float x;
float z;

void update()
{
x = this.GetComponent().x;
z = anothercube.GetComponent().z;
cube.transform.rotation = new Quaternion(x, 0, z, 0);
}

// I understand you should be able to do this since this works - cube.transform.rotation = this.transform.rotation;

Any help is greatly appreciated.

Thanks.

figured it out. I was over thinking the syntax.

x = this.transform.rotation.x;
z = anothercube.transform.rotation.z;
cube.transform.Rotate(x, 0, z);

after playing a bit more i found that rotate is an infinite loop so use this instead

cube.transform.rotation = Quaternion.EulerAngles(x,0,z);