Search Unity

Question Overworld - Jump between scenes

Discussion in 'Getting Started' started by vendaar, Mar 12, 2021.

  1. vendaar

    vendaar

    Joined:
    Dec 15, 2012
    Posts:
    37
    Hello,

    I'm trying to create an overworld a la Super Mario 64 with different portals to go through that will load different scenes.
    My Problem is I don't know how to let my SceneManager know which scene to load.

    I want to give each of my portals a number that I set via script, this could be equivalent to the sceneBuildIndex number for example. This script is attached to each portal. (portal.cs)

    If the sceneBuildIndex equals 1 (Buildindex of my overworld) it should load the scene that i have defined via the script. So you can only go from the overworld to another world. if you go into a portal that is NOT in the overworld, you get just ported back to the overworld.

    GameManager.cs
    Code (CSharp):
    1. public void LevelEnd()
    2. {
    3.     // is the active level the overworld? then load LevelNumber
    4.     if (SceneManager.GetActiveScene().buildIndex == 1)
    5.   {
    6.     Debug.Log("loading" +LevelNumber)
    7.     SceneManager.LoadScene(LevelNumber);
    8.    }
    9.    else //load Overworld
    10.    {
    11.     SceneManager.LoadScene("Level 0");
    12.    }
    13.  
    Here i want to define LevelNumber and then make it so every Number refers to a specific BuildIndex number. but how?

    Portal.cs
    Code (CSharp):
    1. public int LevelNumber;
    2.  
    3. // ????
    I have no good understanding on how to pass variables between different functions and scripts to pls bear with me :)
    Im thankful for any help!


    current BuildIndex Numbers:
    Menu - 0
    Level 0 - 1 (overworld)
    Level 1 - 2
    Level 2 - 3
    Level 3 - 4
     
    Last edited: Mar 12, 2021
  2. vendaar

    vendaar

    Joined:
    Dec 15, 2012
    Posts:
    37
    hope im allowed to bump here, as I'm still stuck at that part. Really grateful for any help or hint.