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 /
avatar image
0
Question by Sajid · Sep 11, 2014 at 09:12 PM · guibuttonarrayselectiongrid

reference array item relative to selectiongrid button

I have a listof strings and a list of textures, both are added/remoted simultaniously, so each item in the list is assosiated with the other in the other string.

For example, my string list might be something like this: {"cube", "sphere", "cone"} while my texture array will be like this: {cubeTexture2D, sphereTexture2D, coneTexture2D}

as you can see, each one has a counterpart in the other list.

I have a selectiongrid that is based off of the texture array, so that it displays a button with each items texture. Here is the relevant code:

     public void AddedItem(string idRecieved){   //function to add items to the inventory, idRecieved is the ID string from our ItemPickup script    
     inventoryStrings.Add(idRecieved);
     inventoryButtons.Add(itemSelectedButton);
     itemSelected = playerCamera.GetComponent<ItemPickup>().itemHit;
     itemSelectedButton = itemSelected.GetComponent<itemIdentity>().identityButton;
     }
 
     void OnGUI(){
         int selectedButton = 0;
         if(isInventoryOpen)
         {
             Screen.lockCursor = false;
             selectedButton = GUILayout.SelectionGrid(selectedButton, inventoryButtons.ToArray(), 10, GUILayout.Height(50));
             Time.timeScale = 0;
             playerCamera.GetComponent<MouseLook>().enabled = false;
             GetComponent<MouseLook>().enabled = false;
         }
         else
         {
             Time.timeScale = 1;
             Screen.lockCursor = true;
             playerCamera.GetComponent<MouseLook>().enabled = true;
             GetComponent<MouseLook>().enabled = true;
         }
         
     }
     
 }


what I want, is in my void OnGUI, I want to have a variable that is equal to the string in the list that is assosiated with it's selectiongrid button. Since selectiongrid returns an int based on what button is selected, I was thinking to do something like:

 public string buttonReference;
 
 buttonReference = inventoryStrings.IndexOf(selectedButton);


But I dont think that will work.

tl;dr: I need to have buttonReference = the list item that is on the selectiongrid button the player presses.

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

2 People are following this question.

avatar image avatar image

Related Questions

Making a set of buttons from an Array 1 Answer

Trying to get an array to make working buttons. [Script Update] 2 Answers

Gathering GameObjects and then creating a button for each GameObject?? 2 Answers

Selectiongrid too many action calls... 1 Answer

sort gui button 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