- Home /
Access specific Text among multiple children
I'm writing UI for a game and Im stuck at a point where I need to access specific text and assign a value for each of it.
Case: Different teams have different number of players and each player has different stats(like strength etc). I have 'n' game objects( n varies depending on the condition). Hence, directly public refering to game obejcts manually is not possible. A Panel has 3 child panels. each child panel has atleast 3 text elements. Each element needs to have a different value.
I have an array of gameobjects. Each gameobject in the array has different text elements. So what im trying is:
cards[1].playerName.text="A" ,
cards[1].Strength.text="90";
cards[2].playerName.text="B" ,
cards[2].Strength.text="40"
and I want to retrieve them :
if(MyTeam=="Team1")
{
int i = 0;
while(i<25 && Cards[i]!=null)
{
Cards[i].gameObject.GetComponentInChildren().text = Team1Roster[i].ToString();
Debug.Log(Cards[i].GetComponentInChildren());
i++;
}
}
In the above method, the topmost Text element is getting selected.
How do I select different text elements from each object.