I’m trying to create a procedural terrain generator based on Simplex Noise.
I have an array of terrain objects and the problem is that when I fill this array with the function Instantiate() but it generates only a reference to the original terrain object so when I edit the heights of a single terrain i get all the terrains with the same shape.
So, how do I copy a Terrain object without reference?
This is the code which generates the tile from the original tile:
int x = (j - buffer / 2) + currentTile.x;
int z = (i - buffer / 2) + currentTile.z;
TerrainTile tile = new TerrainTile (x, z);
tile.tileTerrain = Instantiate (terrainBase, new Vector3 (x * tileSize, 0, z * tileSize), Quaternion.identity) as Terrain;
tile.tileTerrain.transform.gameObject.SetActive (true);
return tile;
TerrainTile is a class i made:
class TerrainTile
{
public Terrain tileTerrain;
public int x;
public int z;
public TerrainTile (int x, int z)
{
this.x = x;
this.z = z;
}
}