I have a "A1" scene, and from there, I want to create a new scene "A2" on button click and then I want to load the same scene. Creating a scene can be done with,
Scene NewScene = SceneManager.CreateScene("A2");
But this scene is an empty scene and as it is not added in build settings so I used
EditorSceneManager.LoadSceneInPlayMode
which would allow me to load scene without having it in build settings. Till here it is going well but now how do I add the maincamera in this new scene programmatically? I have tried something like
public void CreateNewScene()
{
Scene NewScene = SceneManager.CreateScene("A2");
EditorSceneManager.LoadSceneAsyncInPlayMode("A2",new LoadSceneParameters {loadSceneMode = LoadSceneMode.Single});
LoadCamera();
}
public void LoadCamera()
{
Camera camera = gameObject.AddComponent<Camera>();
Instantiate(camera, new Vector3(0, 0, 0), Quaternion.identity);
}
after the new scene is loaded.