简体   繁体   English

Input.GetKeyDown 无法正常工作 Unity3D

[英]Input.GetKeyDown doesn't work properly Unity3D

I have written a simple C# script for player jump(when i press the 'space' button a force is given to player).我已经为玩家跳跃编写了一个简单的 C# 脚本(当我按下“空格”按钮时,会给玩家一个力量)。 But it works like about 2 or 3 times for 10 attempts.但是 10 次尝试大约 2 到 3 次。 What's wrong?怎么了?

public float PlayerJump = 100f;
private void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        rb.AddForce(0, PlayerJump * Time.deltaTime, 0);
    }
}

Note that multiplying the force by Time.deltaTime does not make sense here.请注意,将力乘以 Time.deltaTime 在这里没有意义。 Since it is GetKeyDown, it will only be called for one frame rather than every frame, so this would just make the force depend on the current frame rate the program is running at.由于它是 GetKeyDown,它只会被调用一帧而不是每一帧,所以这只会使力取决于程序运行的当前帧速率。

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

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