using System.Collections;
|
using System.Collections.Generic;
|
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<TileBase> tiles;
|
// Start is called before the first frame update
|
void Start()
|
{
|
tilemap = GetComponent<Tilemap>();
|
GenerateTiles();
|
}
|
|
|
public void GenerateTiles()
|
{
|
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)
|
{
|
if (!tilemap.HasTile(new Vector3Int(x,y+1))) {
|
tilemap.SetTile(new Vector3Int(x, y), ruleTile);
|
}
|
else
|
{
|
tilemap.SetTile(new Vector3Int(x, y), ruleTile);
|
}
|
}
|
|
}
|
}
|
}
|
}
|