Esempio n. 1
0
    public void LoadChunks(Vector3 playerPos, float distToLoad, float distToUnload)
    {
        for (int x = 0; x < world.chunks.GetLength(0); x++)
        {
            for (int y = 0; y < world.chunks.GetLength(1); y++)
            {
                for (int z = 0; z < world.chunks.GetLength(2); z++)
                {
                    float BlockDistanceFromCenter = Mathf.Pow(playerPos.x - x * 16, 2) + Mathf.Pow(playerPos.y - y * 16, 2) + Mathf.Pow(playerPos.z - z * 16, 2);
//                  float dist = Vector2.Distance(new Vector2(x * world.chunkSize,
//                  z * world.chunkSize), new Vector2(playerPos.x, playerPos.z));
                    //Debug.Log("dist: "+BlockDistanceFromCenter);

                    if (BlockDistanceFromCenter < Mathf.Pow(distToLoad, 2))
                    {
                        if (world.chunks[x, y, z] == null)
                        {
                            world.GenChunk(x, y, z);
                        }
                    }
                    else if (BlockDistanceFromCenter > Mathf.Pow(distToUnload, 2))
                    {
                        if (world.chunks[x, y, z] != null)
                        {
                            world.UnloadChunk(x, y, z);
                        }
                    }
                }
            }
        }
    }