Search Unity

shutting down lobby

Discussion in 'Lobby' started by FiF1, Feb 13, 2023.

  1. FiF1

    FiF1

    Joined:
    Feb 23, 2022
    Posts:
    1
    I'm trying to go back to the main menu screen when the game ends and have the lobby shutdown and all the clients leave I tried to have it on the on destroy but that doesn't work

    this is what I have
    Code (CSharp):
    1.  public void GameFinish() {
    2.     Debug.Log("game end");
    3.     if (!IsServer)
    4.     {
    5.         GameFinishServerRpc();
    6.         return;
    7.     }
    8.     Disconnect();
    9.    
    10. }
    11.  
    12. [ServerRpc(RequireOwnership = false)]
    13. void GameFinishServerRpc()
    14. {
    15.     Disconnect();
    16. }
    17.  
    18. public async void Disconnect()
    19. {
    20.    
    21.     using (new Load("Finishing the game...")) {
    22.        
    23.         await MatchmakingService.LockLobby();
    24.         NetworkManager.Singleton.SceneManager.LoadScene("Lobby", LoadSceneMode.Single);
    25.        
    26.        
    27.     }
    28.    
    29. }
    30.  
    31.      public override async void OnDestroy() {
    32.         base.OnDestroy();
    33.         await MatchmakingService.LeaveLobby();
    34.         if(NetworkManager.Singleton != null )NetworkManager.Singleton.Shutdown();
    35.     }
    36.  
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Are you using the lobby service? Why not:
    await LobbyService.Instance.DeleteLobbyAsync(lobby.Id);

    or
    await LobbyService.Instance.RemovePlayerAsync(lobby.Id, playerId);