CustomNetworkManager.checkPlayerCount C# (CSharp) Method

checkPlayerCount() private method

private checkPlayerCount ( NetworkConnection conn ) : IEnumerator
conn NetworkConnection
return IEnumerator
    private IEnumerator checkPlayerCount(NetworkConnection conn)
    {
        yield return new WaitForSeconds(2f);

        print ("LocalPlayersCount: " + ClientScene.localPlayers.Count);
        print("ReadyConnection count: " + ClientScene.readyConnection.playerControllers.Count);

        // There is a bug when after a game match finishes  and a client reconnects to the server, the client is not given a player
        // In such a situation, we can force the server to reload the scene and try to provide all clients a player.

        if(ClientScene.localPlayers.Count > 0 && ClientScene.readyConnection.playerControllers.Count == 0)
        {
            Debug.LogError ("Unknown Error. Player won't spawn");
            ReloadSceneMessage reloadMessage = new ReloadSceneMessage();
            ClientScene.readyConnection.Send (9002, reloadMessage);
        }
    }