如何让Input读取其他键,而不仅仅是Up和Down



我看到一些代码如下:

if (Input.GetKey(KeyCode.UpArrow)) 

if (Input.GetKey(KeyCode.UpArrow))

想知道我如何放置其他钥匙,如";a";

if (Input.GetKey(KeyCode.AArrow))

在这里尝试了这个代码,但它给出了一个错误,就像我写的那样?

在比较中使用KeyCode(如if语句(时,您必须调用要将输入与之进行比较的特定密钥代码。Microsoft有文档提供了System.Windows中表示的标准密钥代码,大多数(如果不是全部的话(外部库都会调用这些代码。

因此,在这种情况下,您需要专门检查A密钥。

if (Input.GeyKey(KeyCode.A))
{
//code runs if and only if the input key is the A key
}
else if (Input.GetKey(KeyCode.Escape))
{
//code runs if and only if the input key is the ESC key.
}

现在,如果您希望在特定时间有许多可能的输入,您可能不希望使用if语句,但我建议您先尝试一下,看看是否能获得更好的结果。

相关内容

最新更新