What's the "Unity way" to create dynamic/generated on-the-fly scenes/sub-maps

Hi all, I’ve only recently begun using Unity and still picking up the ‘right way’ to do things vs. traditional programming, and struggling to find out how to do this - perhaps I’m just not using the right search terminology.

In my example, I have a scene which is the main world the character walks around. In this scene I have buildings that the character can enter. What I’d like is to load a “sub-scene” for the interior of the buildings, but instead of having a pre-made set of scenes I’d like to generate the scene on the fly in code - placing prefabs, lights etc.

What’s the correct way to go about this? Do I make a blank scene with a gameobject which has the generation script attached and reuse this each time I need to load an interior map? Or should I be creating a scene itself somehow in code?

Thanks

I think I understand what you want. Create a new scene(I’ll call it “InteriorSubLevel”), which will be your interior sub level. You should make prefabs of all the interior items you’ll be using (walls, lights, etc. Create a script called “LevelCreate”.

//when  player enters a house...
Application.loadLevel("InteriorSubLevel");//or something like this...

Place your new “LevelCreate” script on your main camera in “InteriorSubLevel”.

//LevelCreate script

//publicly declaring Gameobjects
//drag and drop your prefabs into these spots on your script in the Unity editor
public GameObject interiorPrefab, lightPrefab, chairPrefab, lampPrefab, tablePrefab;

void Start()
{
  //then instantiate all of your prefabs where you'd like them to be
  GameObject interiorGO = (GameObject)Instantiate(interiorPrefab, Vector3.zero, Quaternion.identity);
  GameObject lightGO = (GameObject)Instantiate(lightPrefab, Vector3.zero, Quaternion.identity);    

}//end of Start()

I haven’t tested this. I’m just writing off of memory, but I think this should be what you’re looking for. The other way you could do it, if every interior will have the same amount of interior items, is put all of the interior pieces into your scene as opposed to being prefabs, assign them the same way as the method above (through the inspector), but this time all you’d have to do is change the transform.position to where you want the parts without the “Instantiation”.

 //LevelCreate script
    
    //publicly declaring Gameobjects
    //drag and drop your prefabs into these spots on your script in the Unity editor
    public GameObject interiorGO, lightGO, chairGO, lampGO, tableGO;
    
    void Start()
    {
      //assigning the interior positions
      interiorGO.transform.position = Vector3.zero;
      lightGO.transform.position = new Vector3(10,10,10);
      //...and so on...  
  
    }//end of Start()