Advertisement
Guest User

Untitled

a guest
May 26th, 2019
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. public class ReconnectController : MonoBehaviourPunCallbacks
  2. {
  3.  
  4.     private IEnumerator MainReconnect()
  5.     {
  6.         while (PhotonNetwork.NetworkingClient.LoadBalancingPeer.PeerState != ExitGames.Client.Photon.PeerStateValue.Disconnected)
  7.         {
  8.             Debug.Log("Waiting for client to be fully disconnected..", this);
  9.  
  10.             yield return new WaitForSeconds(0.2f);
  11.         }
  12.  
  13.         Debug.Log("Client is disconnected!", this);
  14.  
  15.         if (!PhotonNetwork.ReconnectAndRejoin())
  16.         {
  17.             if (PhotonNetwork.Reconnect())
  18.             {
  19.                 Debug.Log("Successful reconnected!", this);
  20.             }
  21.         }
  22.         else
  23.         {
  24.             Debug.Log("Successful reconnected and joined!", this);
  25.         }
  26.     }
  27.  
  28.     public override void OnDisconnected(DisconnectCause cause)
  29.     {
  30.         StartCoroutine(MainReconnect());
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement