Search Unity

Question How do you merge two scenes together in Unity?

Discussion in 'Getting Started' started by Asough, Sep 1, 2023.

  1. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    I completed the 2D microgame platformer tutorial some time ago. At the end of the game, there's a door that marks the scene as completed. I want to create my own scene, so that when you enter the door, the player character gets transferred to the new scene that I have created.

    How do you do that?
     
    Last edited: Sep 8, 2023
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,421
    Your script calls SceneManager.LoadScene() with the index or name of the scene. Note that only scenes actually listed in the Build Settings will be included in your built game, and it's those index numbers which you use for this function.

    Any data that you want to carry over should be in a static object, a singleton, or in a GameObject which you have marked as "Don't Destroy On Load," aka DDOL, using the Object.DontDestroyOnLoad() function.
     
    Ruslank100 likes this.
  3. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    Okay, is there no easy way to do it, other than using scripts?

    If not, then I will have to watch a few tutorials on how to do scripts first.
     
  4. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    Focus on making the character moving to the new scene first. Worry about what information you may need from the former scene after that. Some items could probably just be copied from the first scene.

    Find info on the ontrigger event, and the SceneManager functions mentioned above.
     
  5. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    I have already made the character move to the door that finishes the first scene, if that's what you mean?
     
  6. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    when he is at the door, do you have something that confirms this? like a gameobject with ontrigger function?
     
  7. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    Yes. In Assets > Scripts > Mechanics, there is a script called VictoryZone.cs, which marks the scene as completed.

    Victory Zone.png
     
    Last edited: Sep 4, 2023
  8. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    Assuming it has an if-statement for confirming the victoryzone is reached, you could put the SceneManager.LoadScene(scenename/sceneid here) command inside that statement.
     
  9. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    How do I that?

    Should I click open and put it in the VictoryZone.cs script manually?

    VictoryZone.png

    I hope it's okay that I ask, as this is a bit of a new territory for me.

    Are my screengrabs helpful?
     
    Last edited: Sep 8, 2023
  10. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    I just tried typing SceneManager.LoadScene Start (that's the name of the new scene) into the VictoryZone.cs script.

    I now get these error messages:

    Script.png Unity.png
     
    Last edited: Sep 8, 2023
  11. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    You can't put code just anywhere.
    move the scenemanager command inside that if-loop, below ev.victoryZone = this

    and don't forget the ; at the end
     
  12. Chubzdoomer

    Chubzdoomer

    Joined:
    Sep 27, 2014
    Posts:
    130
    I recommend taking some basic coding tutorials. Here's an awesome place to start:
    https://learn.unity.com/learn/pathway/junior-programmer

    And for the love of all that is holy, write your code with a proper IDE like Visual Studio. Trying to code without autocomplete and error highlighting is sheer madness, especially if you're a complete beginner. The Junior Programmer course linked above should cover this as well.
     
  13. Asough

    Asough

    Joined:
    Sep 12, 2022
    Posts:
    151
    I have Visual Studio for Mac installed, if that's what you mean?

    Also, I will take a look at the Junior Programmer Pathway.