//Logs the current player out and puts them back at the login screen.
    private IEnumerator OnLogout()
    {
        var player = Player.localPlayer;                                                            //Grabs the player name based on DaggerUtils.

        if (!player)
        {
            yield return(null);                                                                     //If the player isn't online then return nothing.
        }
        CancelInvoke();
        network.OnClientDisconnect(player.connectionToServer);                                      //Checks to make sure the player has disconnected.

        if (NetworkServer.active)
        {
            network.StopHost();                                                                     //Check if the player is the host if so stop the host as well.
        }
        //wait for disconnect
        //Wait for 20 seconds if the client hasn't disconnected we will return to login screen.
        popup.panel.SetActive(true);
        popup.transform.GetChild(0).transform.GetChild(2).gameObject.SetActive(false);
        popup.transform.GetChild(0).transform.GetChild(0).transform.GetChild(0).gameObject.SetActive(false);

        for (int i = 1; i < 21; i++)
        {
            popup.messageText.text = "Time til logged out: " + (21 - i);
            yield return(new WaitForSeconds(1));
        }

        popup.transform.GetChild(0).transform.GetChild(0).transform.GetChild(0).gameObject.SetActive(true);
        popup.transform.GetChild(0).transform.GetChild(2).gameObject.SetActive(true);
        popup.panel.SetActive(false);

        network.state = NetworkState.Offline;
    }
    //Logs the current player out and puts them back at the login screen.
    private IEnumerator OnLogout()
    {
        var player = Player.localPlayer;                                                                //Grabs the player name based on DaggerUtils.

        if (!player)
        {
            yield return(null);                                                                         //If the player isn't online then return nothing.
        }
        //wait for disconnect
        //Wait for 20 seconds if the client hasn't disconnected we will return to login screen.
        mainMenuPanel.SetActive(false);
        popup.panel.SetActive(true);
        popup.transform.GetChild(0).transform.GetChild(2).gameObject.SetActive(true);
        popup.transform.GetChild(0).transform.GetChild(0).transform.GetChild(0).gameObject.SetActive(false);

        popup.transform.GetChild(0).transform.GetChild(2).GetComponent <Button>().onClick.SetListener(delegate { StopAllCoroutines(); });

        for (int i = 1; i < logoutTimer + 1; i++)
        {
            popup.messageText.text = "Time til logged out: " + ((logoutTimer + 1) - i);
            yield return(new WaitForSeconds(1));

            allowedLogoutTime   = player.lastCombatTime + combatTimer;
            remainingLogoutTime = NetworkTime.time < allowedLogoutTime ? (allowedLogoutTime - NetworkTime.time) : 0;

            if (remainingLogoutTime > 0)
            {
                break;
            }
        }

        if (remainingLogoutTime <= 0)
        {
            if (NetworkServer.active)
            {
                StopAllCoroutines();                                                                    //If this is the server then don't continue.
            }
            CancelInvoke();
            network.OnClientDisconnect(player.connectionToServer);                                      //Checks to make sure the player has disconnected.

            if (NetworkServer.active)
            {
                network.StopHost();                                                                     //Check if the player is the host if so stop the host as well.
            }
            mainMenuPanel.SetActive(false);                                                             //Closes the main menu.

            network.state = NetworkState.Offline;
        }

        popup.transform.GetChild(0).transform.GetChild(0).transform.GetChild(0).gameObject.SetActive(true);
        popup.transform.GetChild(0).transform.GetChild(2).gameObject.SetActive(true);
        popup.panel.SetActive(false);
    }