- Home /
make key as a button
hi,
im using this code to rotate my 3d object
var rotateSpeed = 20.0;
function Update () {
transform.Rotate(Vector3.down, Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime);
// Slowly rotate the object around its X axis at 1 degree/second.
transform.Rotate(Vector3.right, Input.GetAxis("Vertical") * rotateSpeed * Time.deltaTime);
}
i can rotate my objects perfectly with W,A,S,D or the arrows. My quistion is how can i put a Key like W in a gui button. So if you press the gui button(W) it will rotate my object.
greetz
Answer by StephanK · May 27, 2010 at 08:48 AM
var pos : Rect; var pos2 : Rect;
function OnGUI() { if (GUI.Button(pos, "RotateLeft")) { transform.Rotate(Vector3.down, rotateSpeed); } if (GUI.Button(pos2, "RotateRight")) { transform.Rotate(Vector3.up, rotateSpeed); } }
If you want continous rotation (press and hold the button) you will have to use a RepeatButton and multiply rotateSpeed by Time.deltaTime.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
help with errors 2 Answers
[Solved]The Right way of doing PopUp 1 Answer
Move the text in a GUI Button/Box 1 Answer
Disable Mouse Input when OnGUI() 1 Answer