C# 在Update()中返回不停止函数

C# 在Update()中返回不停止函数,c#,unity3d,C#,Unity3d,我有一个问题,其中返回没有停止Update()函数,知道为什么吗 void Update() { if (Input.GetButtonDown("Inventory")) { ToggleInventory(true); return; } if (Input.GetButtonUp("Inventory")) ToggleInventory(false); //FPS Controller functio

我有一个问题,其中
返回
没有停止Update()函数,知道为什么吗

void Update()
{
    if (Input.GetButtonDown("Inventory"))
    {
        ToggleInventory(true);
        return;
    }
    if (Input.GetButtonUp("Inventory"))
        ToggleInventory(false);
    //FPS Controller functions
}
但是,当我按住
inventory
时,下面的功能将继续。
感谢您的帮助

GetButtonDown
仅在第一帧按钮开始按下时返回
true
。因此,下次调用Update时(比按下Inventory按钮的第一帧晚一帧),第一个
if
条件将为false


请参阅文档:

谢谢!我要做的就是调用
GetButton
函数,因为它总是返回true(对吗?)。你认为这太无效了吗?我在Unity方面有点新手,但我希望这会奏效。