I have a healthbar prefab (GameObject) with three children that I wish to modify.
[41066-heiracrchy-2.png*|41066]
I have access to this healthbar via a list.
//instantiates the player rings
for(int i = 0; i < playerList.Count; i++){
healthList.Add (Instantiate(healthBar, new Vector3(i*100+50,0,0), Quaternion.identity) as GameObject);
healthList*.transform.SetParent(healthPanel.transform,false);*
GameObject currHealth = //help!!*
Text currHealthText = currHealth.GetComponent<Text>();*
currHealthText.text = "100";*
GameObject currHealth = //help*
Text maxHealthText = maxHealth.GetComponent<Text>();*
for (int i = 0; i < YourHealthbarGameObject.transform.childCount - 1; i++) {
if (YourHealthbarGameObject.transform.GetChild(i).transform.name == “Current Health”){
YourHealthbarGameObject.transform.GetChild(i).transform.GetComponent().text = “100”;
}
}
for (int i = 0; i < YourHealthbarGameObject.transform.childCount - 1; i++) {
if (YourHealthbarGameObject.transform.GetChild(i).transform.name == "Ring"){
YourHealthbarGameObject.transform.GetChild(i).transform.GetComponent<Image>().fillAmount = 1;
}
}
You can of course create a function and pass the names of the children as a parameter, but this is the basic idea. You iretate over the children and check if the child has the name you want.