Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheItCrOw · Feb 02, 2018 at 01:34 PM · inventoryfor-loopequip

For Loop Problem

Hey, So im making an RPG where u can pick up weapons and then use that one equipped weapon to strike and so on. For that im saving every weapon avaiable in an Array and just set one item active on the player when that one weapon is drawn.

To find the weapon, that should be equipped and therefore set active, a string is passed from one script, that holds the excat weapon name, to the SelectWeapon script which contains the structure above explained.

Everything works just fine, however I just added one more Weapon to the list, and when i now want to equip that, a second Weapon in the list is also set active. So, when I press 1, not only the desired weapon is set active, but also the item at array[1]. I dont know why it suddenly acts in that behaviour. Here is the Code. Thanks in advance.

//CODE STARTS HERE .

  public GameObject[] wl_Col_H;
  public GameObject[] wl_Row_C;

 public static string eqWeaponHand;
 public static string eqWeaponChar;



if(Input.GetKeyDown(KeyCode.Alpha1)) {

         for (int j = 0; j < wl_Row_C.Length; j++)
             {
                 wl_Row_C[j].SetActive(false);

                 if(wl_Row_C[j].name == eqWeaponChar)
                 {
                  wl_Row_C[j].SetActive(true);
                  break;  
                 }
             
        }
Comment
Add comment · Show 2
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
avatar image Bonfire-Boy · Feb 02, 2018 at 01:56 PM 0
Share

It's not clear what your logic is intended to do, but I'm pretty sure it's wrong. You first deactivate the object (implying that you only want the correctly-named object to be active), but then having found the correctly-named object you break out of the loop. So any objects after the (first) correctly-named one won't be checked (and won't be activated or deactivated).

avatar image Nighfox Bonfire-Boy · Feb 02, 2018 at 02:44 PM 0
Share

Exactly. I answered something like that a while ago but I deleted it since he said he already got it working.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TheItCrOw · Feb 02, 2018 at 01:50 PM

Nvm I got it working. It was a stupid mistake, I set that one item at Array[1] somewhere else to always set active when 1 is pressed. The code above works just fine for the explained behaviour.

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.

Follow this Question

Answers Answers and Comments

76 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

Related Questions

[Help] I don't know how to create a stacking system for my inventory! 3 Answers

For Loop Outputting Double 0 Answers

Inventory problem 0 Answers

Buttons in one panel affecting another. 0 Answers

Trying to make a click-and-point kind of thing for an escape game. 0 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