How to get children GameObjects

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>();*
    
  •   	maxHealthText.text = "100";*
    
  •   	GameObject ring = //help here!*
    
  •   	Image ringImage = ring.GetComponent<Image>();*
    
  •   	ringImage.fillAmount = 1;		*
    
  •   }*
    

maybe its possible to use this method?
Unity - Scripting API: Component.GetComponentsInChildren
*

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.

I know this is an old one and is already solved. But I had the same question and created a function:

    private Transform FindChild(Transform parent, string name)
    {
        for (int i = 0; i < parent.childCount; i++)
        {
            Transform t = parent.GetChild(i);
            if (t.name == name)
                return t;
        }
        return null;
    }

I have these game objects:

Cannon
    -Top
    -Bottom
    -Barrel
          -SpawnPoint
          -Cube

I can get the objects with:

        barrel = FindChild(cannon, "Barrel");
        spawnPoint = FindChild(barrel, "SpawnPoint");

I find this one works good for me and its almost 2 Line of code

Transform[] healthBarChildrens;
healthBarChildrens= healthBar.GetComponentsInChildren<Transform>();
currHealth = System.Array.Find(healthBarChildrens, p => p.gameObject.name == "Current Health").gameObject.GetComponent<Text>().text = "100";