2
\$\begingroup\$

I am developing a 2D game, and using an option of the game, it will open a minigame. I planned to set it as a separate scene, but I don't know how could I load a Scene into another scene as a window.

To give you an example, it would be something like Mass Effect and Piracy puzzle (as you can see, the game opens another game in a separate window).

Example:

enter image description here

As you can see, the Minigame is in some kind of Window, and in the background is the main game.

Anybody knows how could I do that?

Thank you

\$\endgroup\$
  • \$\begingroup\$ I never played Mass Effect so I didn't see anything so I'm not sure what exactly you want to achieve. Some minigames are just another camera enabled on demand, other they execute another .exe, but it all depends on what you want to achieve. \$\endgroup\$ – DH. Mar 13 '17 at 20:26
  • \$\begingroup\$ I've posted an image. The idea of the camera is not that simple, because the game uses several scenes, and in all of them, the minigame will be playable. \$\endgroup\$ – programmer23 Mar 13 '17 at 20:34
  • \$\begingroup\$ If your game is 2D - you can just make the game from UI elements. \$\endgroup\$ – Candid Moon _Max_ Mar 13 '17 at 21:15
5
\$\begingroup\$

You can load a scene without destroying anything in the current scene by using the method SceneManager.LoadScene with the LoadSceneMode.Additive flag.

Example: SceneManager.LoadScene ("MinigameSceneName", LoadSceneMode.Additive);

That way all the objects from the loaded scene get added to your current scene. Both scenes now coexist with each other in the same 3d space.

To close the minigame, use SceneManager.UnloadSceneAsync ("MinigameSceneName");

Note that all scripts from the "background scene" are still active, so you might want to set your input controller to inactive while the minigame is active.

The minigame scene won't get loaded "in a window", but you can fix that by the scene being a window in form of an own UI canvas.

If you don't want to implement your minigame with just the UI system, you can add a secondary camera to the scene which shows the minigame. To make that second camera render everything it sees on top of the output of the first camera, set it's "Depth" higher than that of the first camera and set its "Clear Flags" to "Depth Only". You can also edit the "Viewport Rect" of your minigame camera to only draw inside a defined rectangular area. Another feature which could be useful here is the "Culling Mask" which controls which camera renders which layers. When primary game and minigame use different layers, you can easily use culling masks to make sure that they don't interfere with each other visually. For more information, check the documentation of Camera.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ some warning , things like this will require memory space from scene 1 + scene 2 , if scene one already heavy for your computer , adding scene 2 will just make it worse unless you already set up for it . \$\endgroup\$ – user6668201 Mar 14 '17 at 7:08
  • \$\begingroup\$ Thank you Phillip, I will try your method. I was thinking something similar (loading the scene apart and then using a camera to show it as a Window). I'll give it a try. \$\endgroup\$ – programmer23 Mar 14 '17 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.