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 /
This question was closed Jan 15, 2017 at 11:20 AM by Xetros for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Xetros · Jan 16, 2017 at 07:41 AM · unity 5uibuttonarray

Having a hard time getting my GUI button which is generated at runtime to work.

Hi,

Im currently working on my inventory system. Im creating slots based on the items in my inventory. I added a button component to the prefab of the item slot and I am adding the listener via code. However I am running into a error: First off unity is only registering about 25% of my clicks on the button. Ive made sure there are no other UI elements blocking the button and ive also put my eventsystem in Force Module Active mode. Ive tried various other solutions from the internet but couldnt find any that worked.

             for (int j = 0; j <= inventory.Count - 1; j++) {
                 //pressed button is containing an item
                 if (i == j)
                 {
                     //Set sprite to show the item icon THIS WORKS FINE
                     itemSlot[1].sprite = inventory[j].itemIcon;
 
                     //Add the listener(this works until i actually click the button) than throws argument out of range error which is weird since setting the sprite works just fine.
                     itemButton.onClick.AddListener(delegate { checkItemClicked(inventory[j]); });
                     
 
                     Color color= itemSlot[1].color;
                     color.a = 1.0f;
                     itemSlot[1].color = color;
 
                 }
             }

Im pretty new to Unity so I have no idea how to fix these.

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

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Button position scaling weird 1 Answer

UI button in Panel not clickable 2 Answers

im making a multiplayer game, and it has buttons that allow you to craft different blocks, how do I set a reference to the player game object so each player can build different amounts of blocks? 0 Answers

Delay Button Pressed Action after Animation 1 Answer

Button only works once 1 Answer


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