Reload ammo with Clips using variable Substraction

im thinking of a reload weapon with ammunition clips using variables, by using these vars will the concept work:

var ClipAmmo
var GunAmmo

so if R is pressed we do

GunAmmo -= 30;
ClipAmmo = 30;

the gun will shoot if ClipAmmo > 0 and when Instantiate is used i do ClipAmmo–;

will this work, if yes can anyone make up the base of script the instantiate and shoot bullet i got that already, thanks

1 Answer

1

No, it won’t work. Consider the case when there are still bullets in the gun. They will be discarded (perhaps intended?). Also, you have no check of whether the gun is full, and no checks for whether the player actually has 30 bullets. What will you do if they only have 29? Also, your model will be annoying to expand if you want to make another gun with a 60 bullet clip (for example)

On a side note, you shouldn’t instantiate bullets as you shoot them, you’ll get much better performance if you maintain a pool of them