- Home /
ammo cache pickup
ok so im following the unity fps tutorial and everythings fine and dandy but i want to put in ammo crates. therers already health pickups but i want to know if theres any script that allows the player to pickup more ammo....and play a sound
Answer by 0V3RWR173D · Jun 30, 2010 at 10:47 PM
First of all, you will need the model for the crates (or just put a cube with a color or texture on it). The fps tutorial files already comes with a pickup javascript but that does not include a part for the machine gun. You could add a part for the machine gun but that means that you will have to modify the machine gun's script. At the top line of the pickup it shows this:
enum PickupType { Health = 0, Rocket = 1 }
Add to it so that you get this:
enum PickupType { Health = 0, Rocket = 1, Ammo = 20 }
(you can change the "20" to any amount that you want to add to the machine gun)
Under the part of the script that says this:
function ApplyPickup (player : FPSPlayer)
Put this:
else if (pickupType == PickupType.Ammo) {
var ammo : MachineGun = player.GetComponentInChildren(MachineGun);
if (ammo)
ammo.bulletsPerClip += amount;
}
(add it before it says "return true;")
Where it says bulletsPerClip, you are going to have to modify the machine gun script and change that to your other variable.
Now you will not be able to have separate clips for your machine gun, it will just be a certain amount that you have as a total. (without changing the machine gun script it will just change the amount that each clip holds by adding 20)
I am still working on a way to modify the machine gun script so that it is only the total and there are no clips.
I hope that this has helped you. Please tell me if I gave you the wrong information and you want to know something different.
Sounds cool, I've been trying to do the same thing, I made a nice crate model for my Rockets pickup, but having touble trying to get the script from that same tutorial to do the same, Worked well when I added my own health box though.
I'm an artist not a coder so Java script kind of makes me want to go out into a vacant field and let out some primal screams lol
Actually that worked fine for my Rockets, sorry, just tested it out and it even updated my Rockets GUI which I wasn't expecting as i thought maybe I was missing something, Wicked!! Thanks man that's the best piece of advice I think I'vve ever found on here, you ROC$$anonymous$$!!
Well there is a problem i just want to add another clip and not get extra bullets for every clip. I got 30 bullets a clip, then i pick it up and and when i reload i get even more bullets, i get 50 bullets. Change it so you grab a clip ins$$anonymous$$d of more bullets a clip.
Even better still change it so you can pick up a certain amount of "Clips" that way your clips get added to your ammo that way when a clip runs out you have to reaload... now how the Frack is that done?? I've been asking and asking and searching and searching with no answers to that??
Your answer
![](https://koobas.hobune.stream/wayback/20220613063531im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
eating candy, spitting it out. 1 Answer
Script not working at ALL 0 Answers
Help Needed with Shotgun script (SOLVED) 0 Answers