Version: 2022.2

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 的范围十分重要, 则需要限制返回值。

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961