float x = i * 0.1f; // 在 Perlin Noise 计算中加入随机偏移,使每次生成的曲线不同 float y = Mathf.PerlinNoise(i * frequency + randomOffset, randomOffset) * amplitude; positions[i] = new Vector3(x, y, 0);
Mathf.PerlinNoise(i * a, i * a):生成一个平滑波动的 y 值,其中 i * a 控制输入的步长, a 是一个缩放因子,影响噪声的频率。
posArr[i]:用 Perlin Noise 生成的 y 值创建一个三维点位置数组,用于设置 LineRenderer 的路径。
privatevoidGeneratePerlinNoiseLine() { Vector3[] positions = new Vector3[pointCount];
for (int i = 0; i < pointCount; i++) { float x = i * 0.1f; // 在 Perlin Noise 计算中加入随机偏移,使每次生成的曲线不同 float y = Mathf.PerlinNoise(i * frequency + randomOffset, randomOffset) * amplitude; positions[i] = new Vector3(x, y, 0); }