简体   繁体   English

Unity 键盘控制(按下 C# 脚本中的一个键)

[英]Unity keyboard control (press on a key from C# script)

How can I press a key from the C# script?如何按下 C# 脚本中的某个键? All I found it's just how to get click on a key, I did not find how to press programmatically on a key.我所发现的只是如何点击一个键,我没有找到如何以编程方式按下一个键。 How can I do that?我怎样才能做到这一点?

I want to make the key pressed.我想让按键被按下。 Not to check if the key is pressed.不检查键是否被按下。

For example, I want to press Enter with my C# script.例如,我想用我的 C# 脚本按Enter

There is no way in vanilla Unity to simulate a keypress, I believe.我相信,在 vanilla Unity 中没有办法模拟按键。 Based on what you require, it's most likely that you're trying to simulate an event happening.根据您的要求,您很可能正在尝试模拟事件的发生。 What you could do is simply make a function that's going to execute the event that's going to happen when you press ENTER and then call that event whenever it's supposed to be executed.您可以做的是简单地创建一个 function,它将执行您按 ENTER 时将要发生的事件,然后在应该执行的任何时候调用该事件。

It's already been discussed here: How to simulate a key press on button click - Unity这里已经讨论过了: How to simulate a key press on button click - Unity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM