Hello,
I’m programming a grid based game. One of my game logic functions goes through every single element of that grid to do things.
private void GoThroughMap(Action<int,int,int> action)
{
for (x = 0; x < mapX; x++)
{
for (y = 0; y < mapY; y++)
{
for (z = 0; z < mapZ; z++)
{
action(x, y, z);
}
}
}
}
Now I had this in void FixedUpdate
initially and it worked well enough. Until I decided to actually test this with a 1000 by 1000 grid (x and z, y was 1) instead of the 100 by 100 grid I used before. Game performance crashed.
I only need that function every second or so, which I assume would massively reduce the load on my game. But I’m not sure what’s the best way to implement this. Keep it in void update with a float timer to check against? Use InvokeRepeating(string methodName, float time, float repeatRate);
? Some coroutine? Or something else?