Unity3d - Input.GetKey多次返回true [英] Unity3d - Input.GetKey returns true more than once

查看:176
本文介绍了Unity3d - Input.GetKey多次返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用键盘输入将场景中的物体移动。要做这个工作,我创建一个空的游戏对象,并附加一个 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆