- Home /
Destroyable terrain?
Hi
I am wonder how to make a script that I can use to destroy terrain in-game. So if I press a button terrain will be removed at the desired location. Let's take an example, I want to have a station that mines something. And when I press a button then It starts to dig a hole right next to the station. And every second it gets deeper. I know how to program, but I do not know how to make a command that will destroy terrain. So you don't have to write a lot of code that doesn't have anything to do with terrain.
All tips are welcomed!
Answer by daivuk · Mar 29, 2012 at 08:38 PM
You can get the TerrainData from your Terrain from script, and edit it directly. Using GetHeights and then SetHeights with the difference. I didn't test it, but I would presume that performances can be bad if you do this often, say every frame.
But note that you will only be able to dig vertically. Not creating caverns.
How do I access it? How do I access the TerrainData? Can I just use it in a script and add it to the terrain?
Your answer
![](https://koobas.hobune.stream/wayback/20220613065707im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
ExportTerrain doesn't work 1 Answer
Start another thread for a function 1 Answer
Why does script continue executing when turned off or destroyed? 2 Answers
Get Height of Terrain in Script 1 Answer
Freezing on destruction of terrain. 1 Answer