- Home /
Searching for next available empty text field || instantiating object always on top of the hierarchy
Hi ! I'm instantiating buttons and I change the text component of the child using this code :
GameObject go= Instantiate(TESTPREFAB,TESTPREFAB.transform.position,Quaternion.identity) as GameObject;
go.transform.parent = listOfContactsMenu.transform;
TESTTEXT = listOfContactsMenu.GetComponentInChildren<Text>() as Text ;
if(TESTTEXT.text == ""){
TESTTEXT.text = contacts[contacts.Count -1].ContactName;
}
else{
// look for the next empty textfield
}
Now, since i'm using getComponentInChildren it addressed the first text component it finds. This is a problem if I instantiate a secondary button because it'll change the textfield of the first button and leave the second one empty.
I have 2 solutions in my head but I don't know how to execute them.
Possible solution 1 : I need to find a way so that the newest button comes on top of the older ones so that the getComponentInChildren takes the textfield of the newly instantiated button instead of the older one.
Possible solution 2 : I need a way to tell my code the following : if the textfield already contains data, keep searching for another textfield until you find a new one ( I already tried doing that here. well... sort of :D )
Me personally prefer possible solution 1 but i'm open for any answers
Please comment if the question is unclear
Thanks in advance
Your answer
Follow this Question
Related Questions
How do I find a child object in a hierarchy of children? 1 Answer
Disastrous clutter in hierarchy panel due to feature 3 Answers
Make a simple tree 1 Answer
Can I implement Sorting Layers behavior in new UI? 2 Answers
How can I find a unique sibling/parent/child in a specific hierarchy and not from all the scene? 1 Answer