Hello Everyone,
I have a basic script that allows me to reload a gun when it hits 0.
The only problem is that when I reload the gun while it has some rounds left inside, the current amount in the gun gets destroyed and a brand new 6 bullets are put it.
How can I make it that it only reloads up to 6 ammo without destroying the ones already in the gun?
I know there are other things in the script I need to fix as well, but this is the one error I cant seem to figure out. (the rest I'm sure I can figure out)
Any help would be greatly appreciated. Thank you!
here is the script
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 FireHandgun()
{
if (!gunIsHeld)
{
return;
}
if (playerAmmoCount.roundsInRevolver > 0)
{
if (Input.GetButtonDown("Fire1")&& (handgunFire))
{
handgunFire=false;
clone = Instantiate(bulletType, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0, bulletSpeed));
Destroy (clone.gameObject, 0.2);
audio.Play();
particleSystem.Play();
playerAmmoCount.roundsInRevolver -=1; //subtracts 1 round from clip
yield WaitForSeconds(handgunROF);
handgunFire=true;
}
}
}
function ReloadHandgun()
{
if (Input.GetKeyDown("r"))
{
yield WaitForSeconds(playerAmmoCount.reloadtime);
playerAmmoCount.roundsInRevolver +=6;
if (playerAmmoCount.roundsRevolverAmmo <6)
{
playerAmmoCount.roundsInRevolver = playerAmmoCount.roundsRevolverAmmo;
playerAmmoCount.roundsRevolverAmmo -= playerAmmoCount.roundsRevolverAmmo;
}
else
{
playerAmmoCount.roundsRevolverAmmo -=6;
}
}
}
↧