我正在试图弄清楚如何在C#中随机化我的Perlin噪音但是找不到使用我目前拥有的代码的方法。这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PerlinCubeGenScript01 : MonoBehaviour {
public float perlinNoise = 0f;
public float refinement = 0f;
public int multiplier = 0;
public int cubes = 0;
public float darkness;
void Start () {
for (int i = 0; i < cubes; i++) {
for (int j = 0; j < cubes; j++) {
perlinNoise = Mathf.PerlinNoise(i * refinement, j * refinement);
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.transform.position = new Vector3(i, Mathf.Round(perlinNoise * multiplier), j);
int cubeY = (int) Mathf.Round(perlinNoise * multiplier);
Debug.Log(cubeY);
go.GetComponent<Renderer>().material.color = new Color(1, 1, 1, 0f);
}
}
}
void Update () {
}
}
答案 0 :(得分:0)
只要Perlin Noise功能允许您选择2D空间中的任何点,为什么不简单地使用随机数作为种子并从那里开始拾取点?
void Start () {
Random rnd = new Random();
int seed = rnd.Next(Int32.MinValue, Int32.MaxValue);
for (int i = 0; i < cubes; i++) {
for (int j = 0; j < cubes; j++) {
perlinNoise = Mathf.PerlinNoise(seed + (i * refinement), seed + (j * refinement));
// Note that if refinement never changes you are always picking the same point
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.transform.position = new Vector3(i, Mathf.Round(perlinNoise * multiplier), j);
int cubeY = (int) Mathf.Round(perlinNoise * multiplier);
Debug.Log(cubeY);
go.GetComponent<Renderer>().material.color = new Color(1, 1, 1, 0f);
}
}
}