- Home /
Rotating an object in level editor
Okay, so I am making a level editor game in Unity, and I have a few problems with setting the rotation of the object. There is a variable called "selectedObject", that stands for the object that is currently selected and ready to be edited. And there are several textareas for setting the object's Transform.
Here is the code I am working with:
var objectRot : Vector3;
var selectedObject : Transform;
function OnGUI() {
objectRot.x = parseFloat(GUI.TextField(new Rect(40, 120, 50, 20), "" + selectedObject.rotation.x));
objectRot.y = parseFloat(GUI.TextField(new Rect(100, 120, 50, 20), "" + selectedObject.rotation.y));
objectRot.z = parseFloat(GUI.TextField(new Rect(160, 120, 50, 20), "" + selectedObject.rotation.z));
selectedObject.rotation = Quaternion.Euler(objectRot.x, objectRot.y, objectRot.z);
}
Unfortunately there seems to be a problem... Whenever I select an object in game mode, it's rotation snaps to 0 on its own! Also, I cannot set the rotation of the object, as whenever I enter a value into the rotation textarea, the value just snaps back to 0 immediately... :(
Please help!
Did my answer do the trick? Don't forget to mark it as the answer if it did.
Answer by Khada · Aug 19, 2012 at 12:23 AM
Change:
selectedObject.rotation.x
To:
selectedObject.rotation.eulerAngles.x
Going to run a test. I'll update after.
EDIT: Seemed to work for me.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to use target rotation on a configurable joint to make the object point in a certain direction? 2 Answers
Get 360-degree rotation in on-screen directional arrow? 0 Answers
Setting Scroll View Width GUILayout 1 Answer
PasswordField help. 1 Answer