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 /
avatar image
0
Question by DaveBigHead · Nov 06, 2016 at 10:57 AM · textbuttonsincrementaddress

Accessing incremental gameobject names, ie obj1, obj2, obj3, how?!

Despite reading all night various questions that seem quite similar but end up just creating incremental game objects I've had to resort to asking... I'm returning to programming after a good few years away so this is something I have done in the past in C but cant even remember what to call it! I have a number of buttons underneath images and an array tracking the status of those images, so for example an image could be available to buy in which case the button needs to say 'buy me' or ready to sell 'sell me' or empty 'empty'. Each button's text element (.text) is named Available1, Available2, Available3 and each button is named Available1button, etc. So I'm having problems working out the syntax to address a button's text element within a for loop, that is not directly typing in Available3.text (which does work), I want to address it Available+x.text where x is the for count. I thought it would be something like "Available"+x.text = "Sell me"; Many thanks in advance.

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 tanoshimi · Nov 06, 2016 at 12:03 PM

Trying to build dynamic references like this is frowned upon, if not impossible, in most modern programming languages. The correct solution to your problem is to add all of your elements to an array ( GameObject[] AvailableItems;), and then access each element using an index accessor: AvailableItems[0], AvailableItems[1] etc. etc.

Comment
Add comment · Show 1 · 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
avatar image DaveBigHead · Nov 06, 2016 at 02:17 PM 0
Share

Yeah I was starting to think this but at the same time don't really see why, at the end of the day I'm simply asking the game to access a location and to be able to decide which location based on an index...so basically an array...when you think about compilers reducing code down to hex/assembly in the end it's stored as a number, I'm NOT trying to alter the name that the compiler has been given I'm trying to construct the correct name...but hey ho it's a mute point and I'll do it the hard way and build a list in an array. Thanks for the answer.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

UI Text isn't updating text on Button click during the gamePlay [Read description], 0 Answers

Two scrollbar 1 Answer

How to change button text via script? 2 Answers

How to change the text of a button with a name from a list without the name repeating? 2 Answers

UI Relative to screen size 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