Question by
pavansai432 · Jun 14, 2021 at 12:31 PM ·
renderingoptimizationfor-loop
Trying to build a multilevel cube
In a game, I'm working on I'm trying a build 1000 cubes at runtime. Spawning all this cube at the runtime is making my pc lag a bit. So, I want only the face of the cube to display first and not the ones hidden inside. Can anyone help me with how to achieve this? Want this game to be optimized Thanks for the help in advance Here's the code for it:
[SerializeField] GameObject cubePrefab;
[SerializeField] GameObject parentforCubes;
[SerializeField] int rows, columns, depth;
[SerializeField] float padding;
void Start()
{
for (int i = 0; i < depth; i++)
{
for (int j = 0; j < columns; j++)
{
for (int k = 0; k < rows; k++)
{
Vector3 pos = new Vector3(k * padding, j * padding, i * padding);
var spawn = (GameObject)Instantiate(cubePrefab, pos, Quaternion.identity);
spawn.transform.parent = parentforCubes.transform;
}
}
}
}
Comment
Your answer