I use more pictures so you can understand my opinion better.
Here is the video link I recorded.
My code has a problem that I use for to render it and cause it to "lag" for 1-5 seconds, so I need to optimize it, and I found one way is to use chunks, and why I don't use the tilemap and it drops my fps
This links to my map data and my code.
// this is my function I use to create clone game object
if (Vector3.Distance(target.position, topLeft) < 25f
|| Vector3.Distance(target.position, topRight) < 25f
|| Vector3.Distance(target.position, bottomLeft) < 25f
|| Vector3.Distance(target.position, bottomRight) < 25f)
{
// My code is currently running "fine", but when it renders the
// map in 1-2s it will drop fps because of the for loop, then it will increase again
xMin = xMin - 1;
xMax = xMax + 1;
yMin = yMin - 1;
yMax = yMax + 1;
GetCircumjacent();
for (int x = xMin; x < xMax; x++)
{
for (int y = yMin; y < yMax; y++)
{
if (x == xMin || y == yMin || x == xMax - 1 || y == yMax - 1)
{
try
{
int mapX = xCenter + x;
int mapY = yCenter + y;
// this is when I get the prefabs from the array prefabs I added
GameObject clone = Instantiate(prefabs[map[mapX, mapY]], this.transform);
clone.transform.position = zero + new Vector3(x, y);
}
catch (Exception e)
{
Debug.Log("Error: Index out of range");
}
}
}
}
}
private void GetCircumjacent()
{
topLeft = zero + new Vector3(xMin, yMax - 1);
topRight = zero + new Vector3(xMax - 1, yMax - 1);
bottomLeft = zero + new Vector3(xMin, yMin);
bottomRight = zero + new Vector3(xMax - 1, yMin);
}