- Home /
The question is answered, right answer was accepted
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?
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
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 think adding a return;
after _newName.text = _newItem.name
should do the trick.
If not, then I think this 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;
}
}
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:
ball
ballchest
ballchestwrench
ballchestwrenchwrench
ballchestwrenchwrenchwrench
wrenchwrenchwrench << then it puts that to all three item name texts.
@_@ wat. I think its in love with the wrench...
Answer by firejerm · Apr 17, 2018 at 05:27 PM
Well, I got something working. Not as I wanted, but close enough for now.
Basically, I'm going for a hidden 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!