绘制地图可以用很多种方法,实际接触到的地图都是美术制作好的地图,我们需要取灰度图,通过灰度图确认地形起伏,另一种随机生成地图的方法是我们今天主要说的,那就是通过PerlinNoise随机生成地图
1、第一部首先就是通过柏林噪音绘制随机的灰度图
图片最终结果如下:

生成的代码如下:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class CreatTexture : MonoBehaviour
{
//设置图片的大小为128,顶点数不超过65000
int wh = 128;
// Start is called before the first frame update
void Start()
{
Texture2D texture = new Texture2D(wh, wh);
for (int x = 0; x < wh; x++)
{
for (int y = 0; y < wh; y++)
{
//通过perlinNoise生成灰度图
float p = Mathf.PerlinNoise(x * 0.1f, y * 0.1f);
Color color = new Color(p, p, p, 1);
texture.SetPixel(x, y, color);
}
}
texture.Apply();
File.WriteAllBytes(App

最低0.47元/天 解锁文章
2576

被折叠的 条评论
为什么被折叠?



