Hey everyone!
I have a little scripting problem I am unable to wrap my head around concerning checking if points are connected.
So overall I create points at certain positions and, then randomly connect them. The points all remain in a class, which is holds a list containing all indices of the other points this point is connected to.
So since I create the connections randomly it can happen, that not all points are connected to each other, but I want that to happen.
(It also could happen, that the points have no connections, but I managed to exclude this by the method “AddConnectionsNoConnection()”)
for (int i = 0; i < points.Count; i++)
{
for (int j = i + 1; j < points.Count; j++)
{
//method which spits out true or false
bool currentBool = RandomBool();
Debug.DrawLine
(points[i].position, points[j].position, Color.yellow, 5f) ;
if (currentBool == true)
{
points[i].activeConnections.Add(j);
points[j].activeConnections.Add(i);
}
}
}
AddConnectionsNoConnection();
This is the code creating the random connections where “points” is a list of my custom point class.
Does anyone has an idea how I could check if the points can be all visited over connections or if they are in different “groups”? (as shown in the attached image)
And in case there are not connected groups how I can put them in seperated lists?
That might be a quite basic question, I am kind of new to scripting, but if someone could help me out with this that would be great!