Resetting an objects rotation to 0,0,0 by code

For an editor tool I’d like to make a button change the currently selected object to
have it’s Rotation set from whatever it is to 0,0,0 or 1,1,1
I can figure out how to detect the currently selected object,
but how do I code to set the rotation, position or scale to these custom values.

Just rotation will, do I can figure out how to replace the rest if there isn’t much
difference in function…

How do I code to…

1.) Recognise the currently selected object. (Got I think)

2.) Take whatever that objects rotations are along the x,yz
and make each of them Equal zero.


Hi and welcome to Answers.

Check this page first, it shows all the attributes on a GameObject

Look closely at the part called “transform”. That object is where you find the Positions and the Rotation.

When you need to FIND it, GameObject also have a function for that.

If you look into the scripting reference you should have found the Selection class. It holds the current selection. In your case you need something like:

if (Selection.activeTransform != null)
    Selection.activeTransform.localRotation = Quaternion.identity;