Trying to find the grandchildren of a GameObject by using tags to put in a list of Gameobjects that is attatched to the grandparent gameobject.
However, this code is finding ALL the gameobjects with the tag instead of only the gameobject with the tag that are the grandchildren of the Gameobject.
foreach (Transform child in transform)
{
if (child.tag == "ScaleThisCube")
{
if (!child.Equals(transform))
{
cubeobjects.Add(child.gameObject); //first list of gameobjects (puts children with tag ScaleThisCube into a list)
}
}
}
foreach (Transform child in transform) // ThisForeach loop is not working however....
{
cubeobjects.Add(transform.gameObject);
foreach (Transform grandChild in child)
{
if (grandChild.tag == "CubeFace")
{
if (!grandChild.Equals(child))
{
cubefaces.Add(grandChild.gameObject); //second list of gameobjects (puts children of gameobject in the list "CubeObjects" with tag CubeFace into a list)
}
}
}
}