Returns pixel color at coordinates (x, y).
// Sets the y coordinate of the transform to follow the heightmap var heightmap : Texture2D; var size = Vector3 (100, 10, 100); function Update () { var x : int = transform.position.x / size.x * heightmap.width; var z : int = transform.position.z / size.z * heightmap.height; transform.position.y = heightmap.GetPixel(x, z).grayscale * size.y; }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public Texture2D heightmap; public Vector3 size = new Vector3(100, 10, 100); void Update() { int x = transform.position.x / size.x * heightmap.width; int z = transform.position.z / size.z * heightmap.height; transform.position.y = heightmap.GetPixel(x, z).grayscale * size.y; } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public heightmap as Texture2D public size as Vector3 = Vector3(100, 10, 100) def Update() as void: x as int = ((transform.position.x / size.x) * heightmap.width) z as int = ((transform.position.z / size.z) * heightmap.height) transform.position.y = (heightmap.GetPixel(x, z).grayscale * size.y)