- Home /
How to set width and length of terrain via script ?
i couldn't find any solution
thanks
Answer by Eric5h5 · Sep 09, 2012 at 05:59 PM
Use TerrainData.size.
Thanks. Worked for me.
terrain.terrainData.size = new Vector3 (x , y, z);
Is not working for me
Assets/Samuel/RussianAirbaseV2/TerrainSize.cs(12,17): error CS1061: Type UnityEngine.GameObject' does not contain a definition for
terrainData' and no extension method terrainData' of type
UnityEngine.GameObject' could be found. Are you missing an assembly reference?
You need to call GetComponent<Terrain>().terrainData
No, this does not seem to set the size. I set the terrain data size to 128, but the actual terrain is 512 units in "physical size"...
It does set the actual size. Either you misunderstood, or you're doing something wrong. As the docs say, "The total size in world units of the terrain."
So it turns out that if you set the terrain size in the terrain datas object initialization, and then set the height data later, the size gets overwritten. So it is important to set the terrain size after the height data has been set.
Answer by Po0ka · Sep 09, 2012 at 05:43 PM
Via script i don't think it is possible, but you can click on "terrain" on the top left screen, click on "set resolution...", then you can edit the width, length, and height of a terrain. But via script, i have no idea. Ands since when you make a nice terrain and change the resolution, it goes flat and you must remake the map... So editing the size inside of the game qith a script seems improbable.
Setting the size of the terrain doesn't affect the resolution and doesn't clear the heightmap.
You need to resize the terrain with the size, and it is typical to set the resolutions.
int res = (int)(ScenarioBlock.terrainWidth$$anonymous$$eters / ScenarioBlock.height$$anonymous$$ap$$anonymous$$etersPerPoint); TheDeadLinger.tdl.globalTerrain.terrainData.size = new Vector3(ScenarioBlock.terrainWidth$$anonymous$$eters, 1024.0f, ScenarioBlock.terrainWidth$$anonymous$$eters); TheDeadLinger.tdl.globalTerrain.terrainData.alphamapResolution = res; TheDeadLinger.tdl.globalTerrain.terrainData.heightmapResolution = res; TheDeadLinger.tdl.globalTerrain.terrainData.SetDetailResolution(res, 8);
Your answer

Follow this Question
Related Questions
Resizing Unity terrain without resolution 1 Answer
Terrain editor blush smaller then "1" ? 1 Answer
Terrain Size best practices and some sizing questions 2 Answers
Resizing Terrain 1 Answer
Terrain Size (expansion) help. 3 Answers