Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by mrchacko · Aug 26, 2020 at 01:51 AM · programmingshootermono

Arena Shooter Weapon W/ Pickups Scrolling by MouseWheel

Hello All,

I have been struggling for 2 days now on how to implement this properly.

I am trying to design a game where you "pick up" weapons and they move into a predetermined slot. Akin to how Quake or Unreal Tournament played.

While I can get it working perfectly fine with alpha keys, its the mouse scrolling that is throwing me through a loop.

I currently have these variables in my player controller:

 //GUNS GUNS GUNS
 public Gun activeGun;
 public List<Gun> allGuns = new List<Gun>();
 public List<bool> unlockedGuns = new List<bool>();
 public List<Gun> gunsAvailable = new List<Gun>();
 public int currentGun = 0;
 private int previousGun;

I have an equip function:

 public void SwitchGun(int gunNumber)
  {
     if (cannotChangeWeapon) return;
     
     //if (currentGun == gunNumber) return;

     if (gunNumber < 0)
     {
         gunNumber = allGuns.Count - 1;
     }

     if (gunNumber > allGuns.Count - 1)
     {
         gunNumber = 0;
     }

     for (int i = 0; i < unlockedGuns.Count; i++)
     {
         if(i == gunNumber && unlockedGuns[i])
         {
             activeGun.gameObject.SetActive(false);
             activeGun = allGuns[gunNumber];
             activeGun.gameObject.SetActive(true);
             previousGun = currentGun;
             currentGun = gunNumber;
             UIController.instance.ammoText.text = "AMMO: " + activeGun.ammo;
         }
     }
 }

And the pick up function:

  public bool WeaponPickup(string gunToAdd)
 {
     switch(gunToAdd)
     {
         case "Repeater":
             if(unlockedGuns[1] == true)
                 return false;
             else
             {
                 unlockedGuns[1] = true;
                 gunsAvailable.Add(allGuns[1]);
                 return true;
             }
         case "Sniper":
             if (unlockedGuns[2] == true)
                 return false;
             else
             {
                 unlockedGuns[2] = true;
                 gunsAvailable.Add(allGuns[2]);
                 return true;
             }
         case "Rocket Launcher":
             if (unlockedGuns[3] == true)
                 return false;
             else
             {
                 unlockedGuns[3] = true;
                 gunsAvailable.Add(allGuns[3]);
                 return true;
             }
         default:
             Debug.Log("Weapon Pickup ran into a problem with gunToAdd not matching a predefined string.");
             break;
     }

     return false;
 }


One of my friends suggested using a Dictionary with the Gun as a key and the boolean (unlocked) as the value. Since those you can step through. However because Dicts don't show up in the inspector I'd prefer to stick to either an array or a List.

Can anyone help with the code for the mouse wheel scrolling so that it only moves between the guns you've picked up?

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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

224 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 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 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 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 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 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 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 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 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 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 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 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

Coroutine Waits, But Calls Multiple Times per Update. Is There a Way to Fix This? 1 Answer

How could I add "gravity" to a top-down shooter's bullet, such as in The Binding of Isaac? 0 Answers

2 Issues with my SHUMP game 0 Answers

Can I run C# scripts from Unity on an Ubuntu 19.10 macine? Huge stack of compiling errors. 0 Answers

[common programming question] Custom array returns nothing 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges