Hello Everyone,
I am currently adding the finishing touches for a gun script and seem to have run into a bit of a snag.
I have it that ammo is added in a GUI inventory system. Once the ammo item is picked up, it adds a +1 to the players total Ammo amount (int). Once the player reloads the gun the total Ammo count goes down, but the Ammo in the GUI inventory is still there.
How can I get it that once I hit the “R” key to reload, it destroys so-and-so gun ammo from the inventory system? For some reason, I just can’t get my brain around it today.
Here is the code for the shoot/reload function on the gun ( I took out the FireHandgun function)
var bulletType: Rigidbody;
var bulletSpeed = 10;
private var handgunROF = 0.5;
var gunIsHeld : boolean = false;
var playerAmmoCount:ammoCount;
private var handgunFire :boolean = true;
function Update ()
{
FireHandgun();
ReloadHandgun();
}
function ReloadHandgun()
{
if (Input.GetKeyDown("r"))
{
yield WaitForSeconds(playerAmmoCount.reloadtime);
if (playerAmmoCount.roundsRevolverAmmo <6)
{
playerAmmoCount.roundsInRevolver += playerAmmoCount.roundsRevolverAmmo;
playerAmmoCount.roundsRevolverAmmo -= playerAmmoCount.roundsRevolverAmmo;
}
if (playerAmmoCount.roundsRevolverAmmo >6)
{
playerAmmoCount.roundsInRevolver += 6;
playerAmmoCount.roundsRevolverAmmo -= 6;
}
else
{
playerAmmoCount.roundsRevolverAmmo -=6;
}
}
}
Here is the code for the total Ammo count
var roundsInRevolver = 6; //amount of bullets in gun
var roundsRevolverAmmo = 10; //Total ammount of Ammo I have
var reloadtime = 3; //time it takes to reload the gun
function Update ()
{
if (roundsRevolverAmmo <0)
{
roundsRevolverAmmo =0;
}
if (roundsInRevolver <0)
{
roundsInRevolver =0;
}
if (roundsInRevolver >6)
{
roundsInRevolver--;
roundsRevolverAmmo++;
}
}
Would anyone be able to point me in the right direction or show me how to accomplish this? Thank you.