Unity3d - Input.GetKey多次返回true [英] Unity3d - Input.GetKey returns true more than once
问题描述
.cs
文件。 .cs
文件的代码如下: void Update()
{
if(Input.GetKey(up)){
Debug.Log(up);
}
else if(Input.GetKey(down)){
Debug.Log(down);
}
}
我只按一次 strong>,它将输出字符串写入condole 7次。不应该使用这个功能来处理键盘输入?
请参考 http://docs.unity3d.com/ScriptReference/Input.GetKey.html
当用户按住由名称标识的键时,返回true。
如果你看看输入类,你可以找到其他更有用的功能。
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.
这篇关于Unity3d - Input.GetKey多次返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!