- Home /
The question is answered, right answer was accepted
Editor Button Rotates Selected Object
I am working on an editor script and what I am trying to accomplish at the moment is making a button in the editor that when pressed rotates the selected object 90, -90, and 180 degrees. Each of them should be separate buttons. I have the buttons and they are accepted and work just great. The problem is I cant use Selection.transform.Rotate(0,0,0); for some reason.
My code:
if(GUILayout.Button("90"))
{
Selection.transform.Rotate(0,90,0);
}
if(GUILayout.Button("-90"))
{
}
if(GUILayout.Button("180"))
{
}
Error I receive. Assets/Editor/ObjectBuilderEditor.cs(43,35): error CS0117: UnityEditor.Selection' does not contain a definition for
transform'
Ok I have even tried without the slection befor it and I get this error. I am not sure what I would have to do to get rotate the selected object.
Assets/Editor/ObjectBuilderEditor.cs(43,25): error CS0103: The name `transform' does not exist in the current context
UnityEditor.Selection has an Array/Collection of transform(s) in a property called transforms. you will either need to do:
Selection.transforms[0].Rotate(0, 90, 0);
or you will need to iterate through the array and find the Selection you want, remember, the user can select multiple objects in the editor.
as long as you don't want to handle multiple objects, using Selection.activeObject
should work
Answer by _dns_ · Aug 19, 2014 at 03:21 PM
The "Selection" object may not be what you think it is. The answer is in the documentation: http://docs.unity3d.com/ScriptReference/Selection.html
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
Spawn with rotation of 90 on x axis. 1 Answer
Show model Image in Editor Window 0 Answers