未检测到输入(指定输入)

时间:2015-05-14 19:43:48

标签: c# input unity3d

我有以下功能来管理游戏中我的玩家枪的重装过程。我从AmmoCheck函数调用该函数并运行,但if语句永远不会运行,因为输入没有被检测到。这一行:

Debug.Log("重新加载功能检查");

将打印到控制台,但没有更进一步。

我确保在编辑>项目设置>输入下设置了输入,并将其设置为r按钮。 (证明 - http://i.imgur.com/u2aVNpU.png

功能:

void gunReload()
{
    Debug.Log("Reload function check");
    if (Input.GetButtonDown("Reload")) {

        Debug.Log("Reloading");
        if(changeWeapon.currentGun == changeWeapon.gunPistol) {
            aReload.SetActive(false);
            // Incrementing the aClipPistolCurrent value by 1 so the current clip "should" progress one along? idk
            aClipPistolCurrent += 1;
        }
        if(changeWeapon.currentGun == changeWeapon.gunAssault) {
            aReload.SetActive(false);
            // Incrementing the aClipPistolCurrent value by 1 so the current clip "should" progress one along? idk
            aClipAssaultCurrent += 1;
        }

    }       
}

函数调用gunReload();

在Update()

中调用gunAmmoCheck()
void gunAmmoCheck()
{

    if(changeWeapon.currentGun == changeWeapon.gunPistol && aClipPistol[aClipPistolCurrent] > 0) {
        gunFire ();
        // Reducing the ammo of the current clip by 1.
        // ClipPistol is being used (say array, why array
        aClipPistol[aClipPistolCurrent] -= 1;
    }
    if(changeWeapon.currentGun == changeWeapon.gunAssault && aClipAssault[aClipAssaultCurrent] > 0) {
        gunFire ();
        // Reducing the ammo of the current clip by 1.
        // ClipPistol is being used (say array, why array
        aClipAssault[aClipAssaultCurrent] -= 1;
    }

    if(aClipPistol[aClipPistolCurrent] == 0)
    {
        Debug.Log ("Reload");
        // Activating the reload notification on the interface
        aReload.SetActive(true);
        gunReload();
    }
    if(aClipAssault[aClipAssaultCurrent] == 0)
    {
        Debug.Log ("Reload");
        // Activating the reload notification on the interface
        aReload.SetActive(true);
        noAmmo = true;
        gunReload();
    }
}

我在这里不知所措,因为我的所有其他输入工作都完美无瑕。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我刚试过这个并且它有效。我开始认为问题出在你调用函数的地方。还不确定但是

让我们慢慢找到问题。你能否在功能中注释掉那些东西并且只有

 void gunReload ()
    {
        //Debug.Log ("Reload function check");
        if (Input.GetButtonDown ("Reload")) {

            Debug.Log ("Reloading");

        }       
    } 
你的代码中的

。然后从更新中调用 gunReload()并告诉我它是否有效。 从你来调用 gunReload()的函数也是一件好事。

相关问题