Version: 2022.3

Mathf.PerlinNoise1D

切换到手册
public static float PerlinNoise1D (float x);

参数

x The X-coordinate of the given sample point.

返回

float A value in the range of 0.0 and 1.0. The value might be slightly higher or lower than this range.

描述

Generates a 1D pseudo-random pattern of float values across a 2D plane.

Although the noise plane is two-dimensional, you can use a single one-dimensional line through the pattern to good effect, for example for animation effects. The result of PerlinNoise1D(x) is equivalent to PerlinNoise(x, 0), but the former is faster.

using UnityEngine;

public class Example : MonoBehaviour { // "Bobbing" animation from 1D Perlin noise.

// Range over which height varies. float heightScale = 1.0f;

// Distance covered per second along X axis of Perlin plane. float xScale = 1.0f;

void Update() { float height = heightScale * Mathf.PerlinNoise1D(Time.time * xScale); Vector3 pos = transform.position; pos.y = height; transform.position = pos; } }

**注意:**返回值可能略微低于 0.0f 或略微超过 1.0f。如果 0.0 到 1.0 的范围十分重要, 则需要限制返回值。