miepzerino
2023-12-25 c6b7ce89c8d35af5fca62c1ddc97f4b1f5d31f86
Assets/Scripts/GenerateTileMap.cs
@@ -8,8 +8,9 @@
public class GenerateTileMap : MonoBehaviour
{
    public int? seed;
    public int width = 256;
    public int height = 256;
    public int maxWidth = 256;
    public int maxHeight = 384;
    public int maxGroundHeight = 256;
    private float scale;
    private float offsetX;
    private float offsetY;
@@ -59,12 +60,12 @@
    public IEnumerator GenerateTiles(Action finishedCallback, List<Vector3Int> destroyedTiles)
    {
        for (int x = 0; x < width; x++)
        for (int x = 1; x < maxWidth; x++)
        {
            for (int y = 0; y < height; y++)
            for (int y = 1; y < maxGroundHeight; y++)
            {
                float xPerlin = ((float)x / width) * scale + offsetX;
                float yPerlin = ((float)y / height) * scale + offsetY;
                float xPerlin = ((float)x / maxWidth) * scale + offsetX;
                float yPerlin = ((float)y / maxHeight) * scale + offsetY;
                float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin);
                if (perlinNoise >= 0.3f)
@@ -83,6 +84,24 @@
                yield return null;
            }
        }
        for (int x = 0; x <= maxWidth; x += maxWidth)
        {
            for (int y = 0; y <= maxHeight; y++)
            {
                tilemap.SetTile(new Vector3Int(x, y), borderTile);
            }
        }
        yield return null;
        for (int y = 0; y <= maxHeight; y += maxHeight)
        {
            for (int x = 1; x <= maxWidth; x++)
            {
                tilemap.SetTile(new Vector3Int(x, y), borderTile);
            }
        }
        yield return null;
        finishedCallback();
    }
}