What's the general process of changing a Multiplayer game to have offline mode??

Options
Hi there!!
I've been using Photon PUN 2 for making my unity game , I wouldn't say I'm an expert at networking but I've been going quite good with it. The problem I am facing is how do you make the game to work offline. The Photon site says that just the line "PhotonNetwork.OfflineMode = true" will do the work , but when i do that , it gives me an error , saying that it's already connected to the server..Hence I tried to disconnect before accessing the offline mode (I am not sure whether it's the right way or not ) but Here's my code :

public void GoOffline()    // triggered by a button
    {
        if (StatusText != null)
        {
            StatusText.text = "Disonnected!";
        }
        PhotonNetwork.Disconnect();
        Decided = true;   // the amount of players is decided or not 
    }

    
    public override void OnDisconnected(DisconnectCause cause)
    {
        if(StatusText!=null)
        {
            StatusText.text = "Disonnected!";
        }
        

        PhotonNetwork.OfflineMode = true;

        OfflineMode = true;

        StartOfflineLevel();
    }

    public void StartOfflineLevel()
    {
        if(Decided)
        {
            PhotonNetwork.CreateRoom("Off" 
            new RoomOptions()
            {
                MaxPlayers = 1,
                PublishUserId = true,
                IsVisible = false,
                PlayerTtl = 0,
                EmptyRoomTtl = 0
            }, null
            );

            SceneManager.LoadScene(OfNextLevel);  //offline next level
            Decided = true;
        }
    }





When i try to disconnect it says that you can't create a room when outside a lobby and you can't join a lobby when disconnected and you can't run offline mode when connected....can anyone help me with the offline code??

Thanks in advance ,
And yes, Photon has been amazing tool!!
Farhan :blush:

Answers