- Home /
Question by
UnityGISTech · Feb 08, 2019 at 06:54 PM ·
script.resizeterrains
Resize Terrains and adjust Neighbors positions
Hello, is there a way to resize terrain tiles with ScaleFactor and adjust neighbors
i need to do that via scripte :
private void RescaleTerrains()
{
float w_bounds = (maxBounds.x - minBounds.x) * GlobalScaleFactor;
float h_bounds = (maxBounds.z - minBounds.z) * GlobalScaleFactor;
int s_W = Mathf.FloorToInt(w_bounds / TerrainCountX);
int s_H = Mathf.FloorToInt(h_bounds / TerrainCountY);
float offest_X = (w_bounds - s_W * newTerrainCountX) / 2;
float offest_Y = (h_bounds - s_H * newTerrainCountY) / 2;
for (int m = 0; m < terrain.Count; m++)
{
TerrainData tdata = terrain[m].terrainData;
tdata.size = new Vector3(s_W, 0, s_H);
for (int j = 0; j < TerrainCountY; j++)
{
for (int i = 0; i < TerrainCountX; i++)
{
terrain[m].transform.localPosition = new Vector3(minBounds.x * GlobalScaleFactor + i * s_W + offest_X, 0, minBounds.z * GlobalScaleFactor + j * s_H + offest_Y);
}
}
}
}
scale.png
(14.7 kB)
Comment
Your answer
Follow this Question
Related Questions
Unity2D resize the sprite 0 Answers
Script for resize aspect ratio for every device (andorid 2D) ?? 0 Answers
Movement from a CSV File ( Articulation Body ) 1 Answer
Find closest point in triangle to point? 1 Answer
Camera placement / size behavior 3 Answers