Hi all!!
I hope this is the right place to post this specific question.
I have a gun controller script attached to my player object for my FPS game.
The gun controller handles the gun swaps and gun creation from prefabs.
My problem is, when I press a number key to change weapons, the mouse look stops working till the gun is created. Everything else works fine while the gun is created, but not the mouse look. Also when I jump and try to shoot while the player is in the air, it does not work, hold in the shoot button and then jump its fine.
I’m using the FPS controller that comes with Unity’s assets.
Here is the code, not polished and in a completed form as I’d like it but here it is:
void FixedUpdate ()
{
ammoText.text = currentGunAmmo.ToString(); // Update Ammo text
GunSwap(gunSwap); // call this function which calls the gun create function
if(currentGunAmmo == 0) // check if ammo is 0 and all weapons are not empty as well
{
gunsAmmo[currentWeapon] = currentGunAmmo;
GunEmpty(); // function that switches to new gun with ammo
}
if(Input.GetKey("1") && currentWeapon != 0 && gunsAmmo[0] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 0;
gunSwap = true;
}
else if(Input.GetKey("2") && currentWeapon != 1 && gunsAmmo[1] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 1;
gunSwap = true;
}
else if(Input.GetKey("3") && currentWeapon != 2 && gunsAmmo[2] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 2;
gunSwap = true;
}
else if(Input.GetKey("4") && currentWeapon != 3 && gunsAmmo[3] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 3;
gunSwap = true;
}
else if(Input.GetKey("5") && currentWeapon != 4 && gunsAmmo[4] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 4;
gunSwap = true;
}
else if(Input.GetKey("6") && currentWeapon != 5 && gunsAmmo[5] != 0 && canSwap == true) // check if weapon's done shooting
{ // before swapping over
gunsAmmo[currentWeapon] = currentGunAmmo;
currentWeapon = 5;
gunSwap = true;
}
GunBob(); // Gunsway function
}
Thanx!!!