- Home /
 
              This post has been wikified, any user with enough reputation can edit it. 
            
 
            Fps Ammo pickup problem(programming noob)
I'm having trouble with my ammo pickups. I can only pick up a certain kind of ammo with a certain kind of gun, and I need it to pick up the ammo regardless of that as it would in every other kind of shooter.
     if (Physics.Raycast (position, direction, hit, distance, layerMaskAmmo.value)){
         showAmmoGui = true;
         if(hit.transform.CompareTag("Ammo")){
             var pickupGO : Pickup = hit.transform.GetComponent("Pickup");
             
             //ammo for rifles 
             if (pickupGO.pickupType == PickupType.RifleMagazines) {
                 var mags : WeaponScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("WeaponScriptNEW");
                 if(mags != null && mags.firstMode != fireMode.launcher && mags.firstMode == fireMode.auto){
                     notes = "";
                     textFromPickupScript = note;
                     if(pickupp){
                         if(mags.ammoMode == Ammo.Magazines){
                             mags.magazines += pickupGO.amount;
                         }else{
                             mags.magazines += pickupGO.amount * mags.bulletsPerMag;
                         }    
                         audio.clip = pickupSound;
                         audio.Play();    
                         Destroy(hit.collider.gameObject);
                         
                     }
                                     }else{
                     textFromPickupScript = pickupGO.AmmoInfo;
                     notes = notes;    
                 }
             }
             
 
 
                             //ammo for pistol
             if (pickupGO.pickupType == PickupType.PistolMagazines) {
                 var magsp : WeaponScriptNEW = weaponsInUse[weaponToSelect].gameObject.transform.GetComponent("WeaponScriptNEW");
                 if(magsp != null && magsp.firstMode != fireMode.launcher && (magsp.firstMode == fireMode.semi || magsp.firstMode == fireMode.semi)){
                     notes = "";
                     textFromPickupScript = note;
                     if(pickupp){
                         if(magsp.ammoMode == Ammo.Magazines){
                             magsp.magazines += pickupGO.amount;
                         }else{
                             magsp.magazines += pickupGO.amount * magsp.bulletsPerMag;
                         }    
                         audio.clip = pickupSound;
                         audio.Play();    
                         Destroy(hit.collider.gameObject);
                     }
                                     }else{
                     textFromPickupScript = pickupGO.AmmoInfo;
                     notes = notes;        
                 }
             }
 
              
               Comment
              
 
               
              Answer by Fabkins · Jan 25, 2014 at 01:01 AM
looks to me you dont want multiple "if" statements, just a single "if" statement and have "weaponToSelected" be in an index that corresponds to the weapon whose ammo you just selected
Your answer