GetComponentsInChildren

I have a gameobject containing a number of spheres. I’m trying to fill a dictionary with the name and vector3 of each of those spheres.

public GameObject destinations;
Dictionary<string, Vector3> waypoints;

void Start () 
	{
                waypoints.Add(G.name, G.transform.position);
        }

I’m getting the error " foreach statement cannot operate on variables of type UnityEngine.GameObject' because it does not contain a definition for GetEnumerator’ or is not accessible"

How would I use ‘GetComponentsInChildren’ to get the name and location of each of those spheres? Thanks.

Transform[] children = gameObject.GetComponentsInChildren<Transform>();

foreach (Transform t in children) 
{
            waypoints.Add(t.name, t.position);
}

Anyways why do you want to store it in a Dictionary?

I’m trying to track NavAgents by sending the vector to the NavAgent and the position to the GUI, but I realized dictionarys aren’t indexable. I tried defining a struct and creating an array with it. But I couldn’t work out the syntax. Possible a class If I need to store more information, like velocity, distance to next corner or distance to end. For now i’m just going to create a dictionary using the position as the key, and an array of vectors to pull locations from. Then I can pretty easily associate a name with a position.
Is your solution 2D only? I’m working on a multi-story building.Question about NavMeshes. I’m getting artifacts along the top’s of my walls (red arrows) but only the floor meshed are selected when I bake the navmesh. Is there a way to control this? Or can I edit the navmesh manually? Thanks for your time!

My solution is for both 2D and 3D games. However my grid solution does not work with multiple floors.

Cannot help with unity’s solution as i never used it.