public void Build(Dictionary <PieceCoordinates, MapNode> coordinateMap, GameObject rootParentGameObject, int depth) { if (depth <= 0) { return; } List <EConnectionPoints> successfulConnectionsMade = new List <EConnectionPoints>(); foreach (var connection in ConnectionPoints) { if (!CanPlacePieceInConnection(connection, coordinateMap)) { DevTools.Log($"Cannot place piece to the {connection} of piece {gameObject.name}."); continue; } GameObject newPiece = InstantiateRandomPieceAtConnection(connection, rootParentGameObject); coordinateMap.Add(newPiece.GetComponent <MapNode>().Coordinates, newPiece.GetComponent <MapNode>()); successfulConnectionsMade.Add(connection); StartCoroutine(WaitThenBuildAtNode(newPiece.GetComponent <MapNode>(), coordinateMap, rootParentGameObject, depth)); } foreach (var successfulConnection in successfulConnectionsMade) { ConnectionPoints.Remove(successfulConnection); } //TODO: Fix this DevTools.Log($"{gameObject.name} has {ConnectionPoints.Count} connections left"); ContainsEndpoint = ConnectionPoints.Count > 0; }