In top of script i added:
public Transform parentToSearch;
Then:
private void OnGUI()
{
if (hasDescription == true && clickForDescription == true)
{
foreach (Transform child in parentToSearch)
{
if (child.GetComponent<ItemInformation>() != null)
{
ItemInformation iteminformation = child.GetComponent<ItemInformation>();
if (child.name == objectHit)
{
var centeredStyle = GUI.skin.GetStyle("Label");
centeredStyle.alignment = TextAnchor.UpperCenter;
GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 25, 100, 50), iteminformation.description, centeredStyle);
}
}
}
}
}
But when i make the loop:
foreach (Transform child in parentToSearch)
It will find the first level childs of the first parent but this childs have also childs and so on. And i want to loop all the childs and childs of childs under the Transform.
For example in the Hierarchy i have:
- Test
- Test1
- Test2
- Test3
- Test31
- Test32
- Test4
- Test5
- Test51
So now it will loop only over Test 1,2,3,4,5 but I want also to loop over Test31,Test32,Test51