Create and build a scene from the code?

Hello, does anybody know if there’s a way of creating and building (buttons, cubes, etc.) a scene from the code?

The idea is to have a scene that can change depending on the level you are, for example, at level 1 it would have 4 buttons that the player has to press, and at level 2 it would have 8 buttons. Can you change that scene by code? Or should I create a scene fo every level?

Thanks in advance.

Yes, of course. Basically:

int numButtons, levelNum;
if(levelNum == 1) { numButtons = 4;}
else if(levelNum == 2) { numButtons = 8;}
for(int i=0; i<numButtons; i++) { Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity); }

You might want to look through Unity - Scripting API:.