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!