Version: 2023.2

Terrain.SampleHeight

切换到手册
public float SampleHeight (Vector3 worldPosition);

描述

Samples the height at the given position defined in world space, relative to the Terrain space.

This method automatically clamps the world position to the Terrain boundaries.

using UnityEngine;

public class ExampleScript : MonoBehaviour { void LateUpdate() { Vector3 pos = transform.position; pos.y = Terrain.activeTerrain.SampleHeight(transform.position); transform.position = pos; } }