Advertisement
Rakshalpha

LoadChunk

Oct 29th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. public void LoadChunks(Vector3 playerPos, float distToLoad, float distToUnload)
  2.     {
  3.         for (int x = 0; x < world.chunks.GetLength(0); x++)
  4.         {
  5.             for (int z = 0; z < world.chunks.GetLength(2); z++)
  6.             {
  7.  
  8.                 float dist = Vector2.Distance(new Vector2(x * world.chunkSize,
  9.                 z * world.chunkSize), new Vector2(playerPos.x, playerPos.z));
  10.  
  11.                 if (dist < distToLoad)
  12.                 {
  13.                     if (world.chunks[x, 0, z] == null)
  14.                     {
  15.                         world.GenColumn(x, z);
  16.                     }
  17.                 }
  18.                 else if (dist > distToUnload)
  19.                 {
  20.                     if (world.chunks[x, 0, z] != null)
  21.                     {
  22.  
  23.                         world.UnloadColumn(x, z);
  24.                     }
  25.                 }
  26.             }
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement