Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseSamples the height at the given position defined in world space, relative to the terrain space.
function LateUpdate () { transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position); }
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void LateUpdate() { transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def LateUpdate() as void: transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position)