【问题标题】:How do I check whether a player is holding the SPACE key or pressing it?如何检查玩家是按住空格键还是按下它?
【发布时间】:2021-03-04 17:44:13
【问题描述】:

我想将两种攻击方式绑定到同一个键,并根据玩家是按住还是按下来切换它们。

void Attack()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            //do something
        }

        if(Input.GetKey(KeyCode.Space))
        {
            //do something different
        }
    }

【问题讨论】:

    标签: c# unity3d keyboard


    【解决方案1】:

    Input.GetKeyDown 在用户开始按下按名称标识的键的帧期间返回 true,而Input.GetKey 在用户按住按名称标识的键时返回 true。 看来你需要试试 Input.GetKey。

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多