Transfer color from an object to children.,How to transfer colour of an object to objects lower in hierarchy?

Hi,

I am trying to assign the colour assigned to the child NewZealand to the two children in it. Following is the screenshot of the hierarchy,
111746-screen-shot-2018-02-21-at-32048-pm.png

I am using the following script to assign the colour,
string htmlValue = country_color[(index)];

				Color newCol;

				if (ColorUtility.TryParseHtmlString(htmlValue, out newCol))
				{
					countryGameObject.GetComponent<Renderer> ().material.color = newCol;

				}

However, the script changes the colour of only the outside object (NewZealand) and not the two objects in it. Is there any way to do it?

Thanks.,Hello,

I have a child containing 2 children in it.111746-screen-shot-2018-02-21-at-32048-pm.png

When I run the following script to change the colour it changes the colour of NewZealand but not the 2 objects in it.

string htmlValue = country_color[(index)];

					Color newCol;

					if (ColorUtility.TryParseHtmlString(htmlValue, out newCol))
					{
						countryGameObject.GetComponent<Renderer> ().material.color = newCol;

					}

Thanks in advance for the help.

Using GameObject.GetComponentsInChildren<Renderer>() should work for getting the childrens renderers.

More info can be found here GameObject.GetComponentsInChildren<>()

An example would be

Renderer[] childRenderers = countryGameObject.GetComponentsInChildren<Renderer>();

foreach (Renderer r in childRenderers)
{
    //Change colors here
}

This should work:

		string htmlValue = country_color[(index)];
		Color newColor;
		if (ColorUtility.TryParseHtmlString(htmlValue, out newColor))
		{
			Renderer[] r = countryGameObject.GetComponentsInChildren<Renderer>();
			foreach(Renderer m in r)
			{
				m.material.color = newColor;
			}
		}