Question by
Lesnikus5 · Aug 15, 2020 at 07:50 AM ·
terrainterraindatadeformationterrain generationterrain gen
How to edit terrain using TerrainPaintUtility?
There are no usage examples in the documentation. I've tried getting this method to work, but to no avail.
int size = 10;
private Rect terrainSelection;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain")))
{
Terrain ter = hit.collider.GetComponent<Terrain>();
terrainSelection = new Rect(hit.point.x, hit.point.z, 10, 10);
ModifyTerrain(terrainSelection, ter);
}
}
}
public Texture brushTexture;
void ModifyTerrain(Rect selectionArea, Terrain terrain)
{
PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, selectionArea, 10);
TerrainPaintUtility.EndPaintHeightmap(paintContext, "???");
}
Comment