• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Lable · Jan 25, 2014 at 12:32 AM · androidraycastfpsshooterammo

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unrealistic Fps Shooting? 1 Answer

Can you make a FPS multiplayer on a Android or iOS device? 1 Answer

How can i make a raycast in my fps game? 1 Answer

I am making android fps and my raycast shooting button don't work. What I should do? 1 Answer

raycast not doing good 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges