I’ve been translating Inserting heights in TerrainData
everything that’s in comment I don’t know how to translate
#Full Code
using UnityEngine;
using System.Collections;
public class Terraform : MonoBehaviour {
public Terrain terrain ;
public TerrainData tData;
public int xRes ;
public int yRes ;
// public float[,] heights; we don't need it as they are in functions thanks for noticing other than that how should I name it? (float)
public Terrain myTerrain ;
public int xBase = 0;
public int yBase = 0;
void Start () {
//terrain = transform.GetComponent(Terrain);
tData = terrain.terrainData;
xRes = tData.heightmapWidth;
yRes = tData.heightmapHeight;
//terrain.activeTerrain.heightmapMaximumLOD = 0;
}
void OnGUI() {
if(GUI.Button (new Rect (10, 10, 100, 25), "Wrinkle")) {
randomizePoints(0.1f);
}
if(GUI.Button (new Rect (10, 40, 100, 25), "Reset")) {
resetPoints();
}
}
void randomizePoints(float strength) {
var heights = tData.GetHeights(0, 0, xRes, yRes);
for (int y = 0; y < yRes; y++) {
for (int x = 0; x < xRes; x++) {
heights[x,y] = Random.Range(0.0f, strength) * 0.5f;
}
}
tData.SetHeights(0, 0, heights);
}
void resetPoints() {
var heights = tData.GetHeights(0, 0, xRes, yRes);
for (int y = 0; y < yRes; y++) {
for (int x = 0; x < xRes; x++) {
heights[x,y] = 0;
}
}
tData.SetHeights(0, 0, heights);
}
// here I'm trying to make my own version as basics - learning it
void OnMouseDown() {
var heights = tData.GetHeights(0, 0, xRes, yRes);
heights[5,4] = 20;
tData.SetHeights(0, 0, heights);
}
}
EDIT:
- I changed the Question as they figured out array was declared in globally while using in local witch I didn’t notice at all
- trying to do similar version in OnMouseDown(){} but with more control