I have the following function to manage the reloading process of my player's gun in my game. I call the function from an AmmoCheck function and it runs, however the if statement is never run because the input doesn't get detected. The line:
Debug.Log("Reload function check");
will print to the console, but nothing further.
I have made sure the Input is set up under Edit>Project Settings>Input, and it is set to the r button. (Proof - http://i.imgur.com/u2aVNpU.png )
The function:
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;
}
}
}
Function calling gunReload();
gunAmmoCheck() is being called inside of Update()
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();
}
}
I'm at a loss here, since all of my other inputs work flawlessly. Any help would be greatly appreciated.
I just tested this and it worked. I am starting to think that the problem is where you are calling the function from. Not sure yet but
Lets find the problem slowly. Can you comment out those things in your function and have only
in your code. Then call gunReload () from the Update and tell me if it works. It would also be good to pose the function you are calling gunReload () from.