如何检查玩家是否按住 SPACE 键或按下它?
How do I check whether a player is holding the SPACE key or pressing it?
我想将两种攻击方式绑定到同一个键上,并根据玩家是按住还是只是按下来在它们之间切换。
void Attack()
{
if(Input.GetKeyDown(KeyCode.Space))
{
//do something
}
if(Input.GetKey(KeyCode.Space))
{
//do something different
}
}
Input.GetKeyDown returns true during the frame the user starts pressing down the key identified by name, while Input.GetKey returns 当用户按下由名称标识的键时为真。
看来你需要 Input.GetKey 试一试。
我想将两种攻击方式绑定到同一个键上,并根据玩家是按住还是只是按下来在它们之间切换。
void Attack()
{
if(Input.GetKeyDown(KeyCode.Space))
{
//do something
}
if(Input.GetKey(KeyCode.Space))
{
//do something different
}
}
Input.GetKeyDown returns true during the frame the user starts pressing down the key identified by name, while Input.GetKey returns 当用户按下由名称标识的键时为真。 看来你需要 Input.GetKey 试一试。