TerrainData.GetHeights NEED HELP

Im Trying to Make a Terrian Paint Brush but i get a error

UnityException: Trying to access out-of-bounds terrain height information.

public class TerrianBrush : MonoBehaviour {

public Vector3 brushPostion;

public float[,] lastHight;

public Ray ray;
public RaycastHit hit;

// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {
	ray = camera.ScreenPointToRay(Input.mousePosition);
	if (Physics.Raycast (ray,out hit)) {
		brushPostion = hit.point;
	}
	GameObject.Find("Brush").transform.position = brushPostion;
	if (Input.GetMouseButton(0)) {
		lastHight = Terrain.activeTerrain.terrainData.GetHeights(Mathf.RoundToInt(brushPostion.x), Mathf.RoundToInt(brushPostion.y),10,10);
	}
}

}

Apparently, you are accessing the unavailable memory.“Trying to access out-of-bounds terrain height information.”
I suggest you check GetHeights’ param, as far as i know, for example, if your terrain is 10 by 10, and your brush point is just at the right-top corner, “Trying to access out-of-bounds terrain height information.” will happen. so check your params first.
Good luck

Try This. http://unity3d.com/support/documentation/ScriptReference/TerrainData-heightmapHeight.html

:slight_smile:

This might also be helping.

http://unity3d.com/support/documentation/ScriptReference/TerrainData.GetHeight.html

:slight_smile: