- Home /
how do you pick up ammo by clip amount
it's a pretty straight forward simple question. Been trying to mod the Machine gun script into a shotgun script, getting no answers so I'll try and keep it simple.
How do you pick up ammo as clips and have it so when you fire two shots you have to reload? Can't possible make that any simpler ;)
Answer by Dreamer · May 11, 2011 at 01:41 AM
It really depends how you implement your game.
1 Pic up ammo
One way to do it is to trigger the pickup event when your character collide with the ammo object. Attach below script to your ammo object:
function OnCollisionEnter(collision : Collision) {
if(collision.tag="Player"){
ammo+=2;
Destroy(this.gameObject);
}
}
2 reload
var ammo_count:int=2; var reloading_time:float=5;
function Update(){ //if have loaded ammo if(ammo_count>0){ fire();//your own fire function //include below 2 statements at end your fire function ammo_count-=1; ammo-=1; } //if have unloaded ammo, start reloading else if(ammo>0){ reloading_time-=Time.deltaTime ; if(reloading_time<0){ if(ammo>2) ammo_count=2; else ammo_count=1;
//reset reloading time reloading_time=5; } }
Ahh thank the Gods, someone willing to help. ;) Please take a look here: http://answers.unity3d.com/questions/57969/help-needed-with-shotgun-script
This is how my scripts are arranged, but what happens is, is that when I pick up ammo for the shotgun it just adds the whole amount to my GUI. So my shotgun never reloads after 2 shots, because it SHOULD be 2 shots per clip at 12 X 2 per pickup or 24 in each pick up box.
Can you help me out?
Your answer
![](https://koobas.hobune.stream/wayback/20220613133358im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help Needed with Shotgun script (SOLVED) 0 Answers
What is going on with this pickUp Script? 1 Answer
Need help with picking up items by typing "E" 0 Answers
How can I keep my ammo count going over the cap? 1 Answer
Pick Up Script "overflowing" 4 Answers