Version: 2017.2

Terrain.SampleHeight

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

描述

在相对于地形空间的给定位置(以世界空间定义)进行高度采样。

using UnityEngine;

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