Hi, so my world generation script is working just fine but there is a problem that is causing lag and that is that when I instantiate too many objects it becomes laggy, I mean I have an area of about 40x40 blocks and it lags just then, and the reason to that is because I’m instantiating, but however, if there’s any way to display only what’s visible and not render all the other sides of the blocks then that would save a lot of performance power, but how do I do that? Do I make a script that always renders the visible content of the object and then attach that to the prefab that I’m instantiating? Or something like that?
Here’s my world generation script:
var player : Transform;
var origin : Transform;
var width_x : int;
var width_z : int;
var depth : int;
var blocks : GameObject[];
function Start () {
for(var x : int = 0; x < width_x - 1; x++){
for(var y : int = 0; y > -depth - 1; y--){
for(var z : int = 0; z < width_z - 1; z++){
Instantiate(blocks[Random.Range(0, blocks.Length)], new Vector3(x, y, z), Quaternion.identity);
}
}
}
}