I want to move my object on scene using keyboard inputs. To do this work, I create an empty game object and attach a .cs
file to it. Code of this .cs
file is below :
void Update()
{
if (Input.GetKey ("up") ) {
Debug.Log("up");
}
else if (Input.GetKey ("down") ) {
Debug.Log("down");
}
}
I press up key only once, it writes output string on condole 7 times. Shouldn't I use this function to handle keyboard input?
Please refer to http://docs.unity3d.com/ScriptReference/Input.GetKey.html
Returns true while the user holds down the key identified by name. Think auto fire.
If you look at the input class you can find other functions which will be more useful.