Unity3d - Input.GetKey returns true more than once

心不动则不痛 提交于 2019-12-12 01:47:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30727530/unity3d-input-getkey-returns-true-more-than-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!