找回密码
 立即注册
查看: 425|回复: 4

unity3d开发请问这个问题出在哪要如何去解决?

[复制链接]
发表于 2020-12-29 10:26 | 显示全部楼层 |阅读模式
unity3d开发请问这个问题出在哪要如何去解决?
发表于 2020-12-29 10:32 | 显示全部楼层
你没有理解GetButtonDown这个API的含义,其中的参数buttonName并不是指键盘上的按键。
上官方文档
Returns true during the frame the user pressed down the virtual button identified by "buttonName".
You need to call this function from the Update function, since the state gets reset each frame. It will not return true until the user has released the key and pressed it again.

Use this only when implementing action like events IE: shooting a weapon.
Use Input.GetAxis for any kind of movement behaviour.

To edit, set up, or remove buttons and their names (such as "Fire1"): 1. Go to Edit > Project Settings > Input to bring up the Input Manager. 2. Expand Axis by clicking the arrow next to it. This shows the list of the current buttons you have. You can use one of these as the parameter "buttonName". 3. Expand one of the items in the list to access and change aspects such as the button's name and the key, joystick or mouse movement that triggers it. 4. For more information about buttons, see the Input Manager page.
翻译一下:
当用户按下了被表示为“buttonName”的虚拟按钮的那一帧时间内,返回true。
由于每一帧Input状态都会重置,所以你应该在Update函数中调用这个函数。在用户释放此按钮并且重新按下的之前不会返回true。
只有当事件类的操作比如:武器开火才应该使用这个,对于类似移动操作请使用Input.GetAxis。
编辑、设置、或者移除buttons及其名字(比如“Fire1”):1.前往Edit > Project Settings > Input,打开InputManager。2.点击下拉按钮展开Axis,这里展示了所有你当前的buttons。你可以使用它们中的任一个作为参数“buttonName”。3.展开列表中的某一项来查看或者修改属性,比如button的名字,key,joystick或者鼠标移动等等。4.更多关于buttons的信息,请查看 Input Manager 页面。


所以遇到问题前,先查阅官方文档(在Unity编辑器中点击问号图标可以直接打开本地文档),然后Unity Answer,Unity Forum,再然后StackOverflow,最后还有Google。
说实话来知乎提这样的问题,效率实在太低了。类似你这样的问题,我一天能碰到几十个,如果每个都来知乎提个问,那根本没法干活。所以一个小建议就是:学习或者使用一个新的工具,先找到它的官方文档,用户社区,打开搜索引擎,以备随时解决困难
发表于 2020-12-29 10:39 | 显示全部楼层
请照着报错里第二小行导航到input菜单里设置你的按键映射,能英语好点就多学下基本的英语,能谷歌就谷歌,能百度就百度,最后再来知乎问
发表于 2020-12-29 10:43 | 显示全部楼层
这个是单纯的没看懂api.....
发表于 2020-12-29 10:49 | 显示全部楼层
按键定义不对啦
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-20 08:53 , Processed in 0.067339 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表