- Home /
Key input to rotate object
I'm trying to get an object to rotate a full 360 degrees with a single key stroke. but i'm not sure how to get it to work.
I've got the basic key input for the keystroke. but I'm unsure about the actual rotation of the transformed object
Answer by Borgo · Sep 12, 2011 at 05:42 PM
You can use something like this:
if(Input.GetButton("ButtonToRotate")){
objectYouWantoToRotate.transform.localEulerAngles.x += 10 * Time.deltaTime;
}
I did'n test this code.
Change localEulerAngles to eulerAngles if you need a Global Rotation.
Change the "x" to whatever axis you want.
You can chage the "Input.getButton" to "Input.getAxis(String:axis)" or "Input.GetKey(Keycode:key)"
this might sound like a simple error but " error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.eulerAngles'. Consider storing the value in a temporary variable"
I'm honestly drawing a blank on how to solve the issue
It's because you are using C#, in C# you cannot modify a struct Item, you need to set a new Object or mutiply with another Object like this
objectYouWantoToRotate.transform.localEulerAngles = new Vector3(10 Time.deltaTime, 1, 1);
Answer by kgoswami · Sep 13, 2011 at 03:21 AM
http://unity3d.com/support/documentation/ScriptReference/Transform.RotateAround.html
if(Input.GetButton("Jump"))
{
objecttorotate.transform.RotateAround(Vector3(0,1,0),360);
}
Your answer
Follow this Question
Related Questions
Rotation-Trouble 4 Answers
Transform.Rotate not stopping? 1 Answer
Scale gameObject 1 Answer
How to prevent Z axis rotation ? 1 Answer
How to Rotate Game Object in specific Angle repeatedly on Key Press? 1 Answer