- Home /
Rotate Object Via GUI
What is the best way to rotate an object (on the z axis) with a GUI component? I am making a kind of sandbox/create style game, and for scaling, I used a horizontalslider by setting the objects localscale.
Answer by DaveA · Mar 19, 2011 at 08:17 PM
It's really up to you, or you could google studies on user interaction and usability. You could use a slider for that, or a couple of buttons (rotate counterclockwise, rotate anti-counterclockwise), or detect a drag on the object itself.
Thanks for the quick response! I think that I will use another horizontal slider, just to go with the flow of things. But when I tried to do this before, it was very buggy, and only worked if I called the objects transform.rotation. What should I do?
Yeah you'd map the slider's value to (I'm guessing) 0 to 360 and set that to object's transform.rotation.z
Or use transform.Rotate() and feed it a degree, which would be applied per-frame. So send small values of essentially delta-z-rotation, then your slider would be like a 'rotate velocity'
yeah, I did try using 0 to 360, but it seemed that it only worked with 0 to 1. But even then it didn't rotate the object properly, and glitched when going backwards. I've just tried doing transform.Rotate(), but it doesn't work the way I'd want it to. As you said, it would be like a "rotate velocity". There is also quite a lot of lag applied because it is rotating it every frame.
Answer by rhose87 · Oct 27, 2011 at 12:32 PM
can you post your code here, because i have the same problem and don't know what to write.
Your answer
Follow this Question
Related Questions
GUI slider and rotation not working 1 Answer
GUILayout formatting help 1 Answer
GUILayout Textfield not editable just static 1 Answer
Using treeview OnGUI with GUIlayout 0 Answers
How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers