set the rotation to zero

Hi guys

I am working on creating a tank game & have this little problem im stuck with so here it goes

I have a gun mounted on the tank which i can rotate in any direction i want, wat i want to do is after i have rotated it in any direction the rotation of the gun should remain and the pivot should again get reset to the local axis i think Smile that is after i have rotated it once the pivot also gets rotated in the same direction i want to get reset just like freeze transformation in "Maya".

thankyou

Something like this should work:

from the gun script (in js):

var rot = transform.rotation;
transform.parent.rotation = Quaternion.identity;
transform.rotation = rot;