Hi dear members,
Is having a “break” in a “foreach” loop -that is itself inside a “for” loop- breaking both loops (foreach is the direct one where the “break” command is called, but foreach is itself nested in a for loop) or only the direct one (foreach)?
I get no errors, but the behavior is not EXACTLY how I intend it to be, so I am wondering if the problem can originate from how the break command behaves… I want to stop the foreach loop on break, however the for loop should go on until g<4.
Part of my code I wonder about:
for (g=1;g<4;g++)
{
if (g == 1)
{
gos = GameObject.FindGameObjectsWithTag("crabtag");
}
else if (g == 2) {
gos = GameObject.FindGameObjectsWithTag("turtletag");
}
else if (g == 3)
{
gos = GameObject.FindGameObjectsWithTag("jellytag");
}
foreach(GameObject go in gos)
{
if (playerposx == go.transform.position.x && playerposy == go.transform.position.y)
{
if (g == 1)
{
crabHere = true;
break;
}
else if (g == 2)
{
turtleHere = true;
break;
}
else if (g == 3)
{
jellyHere = true;
break;
}
}
else
{
if (g == 1)
{
crabHere = false;
}
else if (g == 2)
{
turtleHere = false;
}
else if (g == 3)
{
jellyHere = false;
}
}
}
}