• 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 Apr 20, 2018 at 04:51 AM by firejerm for the following reason:

The question is answered, right answer was accepted

avatar image
Question by firejerm · Apr 16, 2018 at 09:35 PM · gameobjecttextlists

Dynamically assign each ui.Text.text in list to the name of objects in another list

Sooo...another sleepless night(thanks insomnia)

What I'm trying to do is 1) Dynamically build a list of items from resource folder. (That works right)

2) Dynamically build a list of UI text objects from another resource folder. (that works too)

3) Dynamically assign Each one of the UI texts.text to be the Item names. --Thats where I am having trouble at.

Instead of renaming each text to each name, it only names each one to the last Item's name.

Oh where did I go wrong?

alt text alt text

itemholder.jpg (107.9 kB)
itemholder-cs.jpg (65.5 kB)
Comment

People who like this

0 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 $$anonymous$$ · Apr 16, 2018 at 09:55 PM 0
Share

Not sure If I'm understanding your code right but I believe on line 45 you want to replace _newItem.name with _Item.name. Otherwise you're just assigning the last item in the list that was made on line 35

avatar image firejerm $$anonymous$$ · Apr 16, 2018 at 11:52 PM 0
Share

no, that didn't do anything

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by MechaWolf99 · Apr 17, 2018 at 02:23 PM

My guess would be because you are looping through all the objectsToFind. And so it is only setting the last one. I t$$anonymous$$nk adding a return; after _newName.text = _newItem.name should do the trick.
If not, then I t$$anonymous$$nk t$$anonymous$$s should. Maybe.

  for (int i = 0; i < objectsToFind.length; i++)
             {
                  _newName = (GameObject)Instantiate(objectToFind(i))
                 for (int j = 0; j < ItemName.length); j++)
                 {
                         _newName.text = _newItem.name;
                 }
              }
 

Comment
firejerm

People who like this

1 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 firejerm · Apr 17, 2018 at 05:30 PM 0
Share

I got a modified version of your code working. What you posted above was for arrays. I was thinking of using one.

The code above adapted to a list still made 3 wrench on all 3 item texts...

debug log was like:

  1. ball

  2. ballchest

  3. ballchestwrench

  4. ballchestwrenchwrench

  5. ballchestwrenchwrenchwrench

  6. wrenchwrenchwrench << then it puts that to all three item name texts.

    @_@ wat. I think its in love with the wrench...

avatar image

Answer by firejerm · Apr 17, 2018 at 05:27 PM

Well, I got somet$$anonymous$$ng working. Not as I wanted, but close enough for now.

Basically, I'm going for a $$anonymous$$dden object game in 3d. Not the 2d, stare at a picture kind.

so far I have: for (int o = 0; o < objectsToFind.Count; o++) { _newItem = (GameObject)Instantiate(objectsToFind[o]); ItemName.text += _newItem.name; Debug.Log(ItemName.text); }

That shows each instantiated item's names in 1 text. Next steps are to remove the "(clone)" from the names and add spaces in between each name.

Then when item clicked, remove its name from the text list.

Thanks for the help!

Comment

People who like this

0 Show 0 · 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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Setting a game object from a list to be the active character that gets instantiated 1 Answer

Access specific Text among multiple children 0 Answers

How to display text on a gamebject? 3 Answers

How do I add new instances of a object into a list? 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