Terrain.SampleHeight

function SampleHeight (worldPosition : Vector3) : float

Description

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

JavaScript
function LateUpdate () {
transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position);
}

using UnityEngine;
using System.Collections;

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

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def LateUpdate():
transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position)