using System; using System.Collections; using UnityEngine; using UnityEngine.Tilemaps; public class GenerateTileMap : MonoBehaviour { public int width = 256; public int height = 256; public float scale = 20f; public float offsetX = 0f; public float offsetY = 0f; Tilemap tilemap; public RuleTile ruleTile; //public List tiles; private void Awake() { tilemap = GetComponent(); } public IEnumerator GenerateTiles(Action finishedCallback) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float xPerlin = ((float)x / width) * scale + offsetX; float yPerlin = ((float)y / height) * scale + offsetY; float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin); if (perlinNoise >= 0.3f) { tilemap.SetTile(new Vector3Int(x, y), ruleTile); } } // Update UI every 8 lines if ((x % 8) == 0) { yield return null; } } finishedCallback(); } }