Leave room and change scenes

Options
My problem is that I am making a game, and when I give start game, it changes me to scene 1, and the menu is in scene 0, so I want to leave the room and change the scene to be in the menu, but my problem is that it tells me that my script called Menu is destroyed and it also tries to change the scene without calling the menu, it changes the scene, but nothing comes out, and I try to activate the menu manually, and nothing comes out
the code for the menu:
public string menuName;
    public bool open;

    public void Open()
    {
        open = true;
        gameObject.SetActive(true);
    }

    public void Close()
    {
        open = true;
        gameObject.SetActive(false);
    }

the code of the menu manager:
public static MenuManager Instance;

    [SerializeField] Menu[] menus;

    void Awake()
    {
        Instance = this;
    }

    public void OpenMenu(string menuName)
    {
        for(int i = 0; i < menus.Length; i++)
        {
            if (menus[i].menuName == menuName)
            {
                menus[i].Open();
            }
            else if (menus[i].open)
            {
                CloseMenu(menus[i]);
            }
        }
    }

    public void OpenMenu(Menu menu)
    {
        for (int i = 0; i < menus.Length; i++)
        {
            if (menus[i].open)
            {
                CloseMenu(menus[i]);
            }
        }

        menu.Open();
    }

    public void CloseMenu(Menu menu)
    {
        menu.Close();
    }

the code that leaves the room and changes the scene:
public void Leave()
    {
        Launcher.Instance.LeaveRoom();
        Destroy(RoomManager.Instance.gameObject);
        SceneManager.LoadScene(0);
    }
the Launcher.Instance.LeaveRoom() is calling the PhotonNetwork.LeaveRoom and the Menu, With that line of code, it does not change the scene, and I get the error I said above.

I change it only to call the PhotonNetwork.LeaveRoom and [url][/url]changes the scene, but nothing comes out


Best Answer

  • hannahmontanna
    Answer ✓
    Options
    you fundamentally can't do this, because once you leave the room, you leave the session, and have to set it back up again. do what you want to do, but dont leave the game session/room. If autosyncscene = false, you can change scenes independently of master client, and use network culling or something to stop crosstalk.

Answers

  • hannahmontanna
    Answer ✓
    Options
    you fundamentally can't do this, because once you leave the room, you leave the session, and have to set it back up again. do what you want to do, but dont leave the game session/room. If autosyncscene = false, you can change scenes independently of master client, and use network culling or something to stop crosstalk.