How to match rotation of two objects?

Hi,

I have been searching all over the www but cannot find anything that works yet…

Let’s say I have two objects, one starts to rotate on it’s Z Axis…
How can I match rotation of two objects so both would rotate exactly the same on the Z Axis?

My code so far:

var obj1: GameObject; 
var obj2: GameObject; 
 
function Update () {
obj1.transform.rotation = Quaternion.Euler(0.0f, obj1.transform.rotation.eulerAngles.y,  obj2.transform.rotation.eulerAngles.z);
}

Thanks,
Kim

Got it working now! Many thanks for your most excellent help Robertbu!
I had to add the axis at the end of:
obj1.transform.localRotation = obj2.transform.localRotation;

So what made it work for me was:
obj1.transform.localRotation.z = obj2.transform.localRotation.z;

Nice one line of code!
Thanks again.