I use 9 similar for loops to create such hexagon which is made up of smaller hexagons.
My question is How do I replace 9 for loops with just 1 for loop? Any ideas, much appreciated.
Middle column
(x=0,y=(-4;4)
for (int x = 0; x < 1; x++)
{
for (int y = 4; y > -5; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
First column right
(x=1,y=(-3.5;3.5))
for (float x = 0.75f; x < 1.75; x++)
{
for (float y = 3.5f; y > -4.5; y--)
{
Instantiate(cell, new Vector2(x,y), Quaternion.Euler(0.0f,0.0f,90.0f));
}
}
Second column right
(x=2,y=(-3;3))
for (float x = 1.5f; x < 2.5f; x++)
{
for (int y = 3; y > -4; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
Third column right
(x=3,y=(-2.5;2.5))
for (float x = 2.25f; x < 3.25; x++)
{
for (float y = 2.5f; y > -3.5; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
Fourth column right
(x=4,y=(-2;2))
for (int x = 3; x < 4; x++)
{
for (int y = 2; y > -3; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
First column left
(x=-1,y=(-3.5;3.5))
for (float x = -0.75f; x < 0.25; x++)
{
for (float y = 3.5f; y > -4.5; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
Second column left
(x=-2,y=(-3;3))
for (float x = -1.5f; x < -0.5f; x++)
{
for (int y = 3; y > -4; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
Third column left
(x=-3,y=(-2.5;2.5))
for (float x = -2.25f; x < -1.25; x++)
{
for (float y = 2.5f; y > -3.5; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
Fourth column left
(x=-4,y=(-2;2))
for (int x = -3; x < -2; x++)
{
for (int y = 2; y > -3; y--)
{
Instantiate(cell, new Vector2(x, y), Quaternion.Euler(0.0f, 0.0f, 90.0f));
}
}
And I need this: One formula creates the whole hexagon
