I am trying to create a basic C# script that allows me to alter a particular spot of terrain in game.
This is what I’ve come up with so far,
using UnityEngine;
using System.Collections;
public class ChangeTerrainHeight : MonoBehaviour {
public Terrain TerrainMain;
void OnGui()
{
if(GUI.Button(new Rect(20, 40, 200, 30), “Change Terrain Height”))
{
//get the terrain heightmap width and height.
int xRes = TerrainMain.terrainData.heightmapWidth;
int yRes = TerrainMain.terrainData.heightmapHeight;
//GetHeights - gets the heightmap points of the terran. Store those values in a float array.
float [,] heights = TerrainMain.terrainData.GetHeights(0, 0, xRes, yRes);
//Manipulate the height data
heights[10, 10] = 1f; //0 - 1. 1 being the maximum possible height
//SetHeights to change the terrain height.
TerrainMain.terrainData.SetHeights (0, 0, heights);
}
}
}
//This script is put on my terrain which is named TerrainMain
All it is supposed to do is create a button and when I click on that button it is supposed to change the height of the terrain at 10, 10 to its limit. I am not even getting a button when I play.
Thanks for any/all help