Right I found this question asked elsewhere but I am really stuck at the point where none of the solution is unfortunately working.
So when the game gets over, I have to load either the menu screen or random battle screen or the friends screen. But somehow I am trying my heart out to disconnect when I click the random screen button and friends screen button. But it is just not disconnecting.
The code is as follows:
public class GameOverManagerMP : MonoBehaviourPunCallbacks
{
public void OnClickRandomScreenButton()
{
MultiPlayerScoreManager.instance.NextSceneToBeLoaded =
"MatchMakingScreen";
PhotonNetwork.LeaveRoom();
}
public void OnClickFriendsScreenButton()
{
MultiPlayerScoreManager.instance.NextSceneToBeLoaded = "FriendsScreen";
PhotonNetwork.LeaveRoom();
}
public override void OnLeftRoom()
{
Debug.Log("On left room executed in Game Over Manger class.........");
base.OnLeftRoom();
PhotonNetwork.Disconnect();
}
public override void OnDisconnected(DisconnectCause cause)
{
Debug.Log("On OnDisconnected executed in Game Over Manger class.........");
base.OnDisconnected(cause);
SceneManager.LoadScene( MultiPlayerScoreManager.instance.NextSceneToBeLoaded );
}
}
So basically I got the error the is attached here:
operation leaveRoom(254) not called because Client is not............
So what I did was I put
if(PhotonNetwork.InRoom)
PhotonNetwork.leaveRoom()
The error disappears but nothing happens, meaning the OnDisconnected Callback never executes...
I even tried this code
if (PhotonNetwork.IsConnected)
{
StartCoroutine(Disconnect());
}
IEnumerator Disconnect()
{
PhotonNetwork.Disconnect();
while (PhotonNetwork.IsConnected)
{
yield return null;
Debug.Log("Disconnecting. . .");
}
Debug.Log("DISCONNECTED!");
}
But it doesn't hit the line "DISCONNECTED!". It is in an infinte loop with saying "Disconnecting..."
The whole part is when I stop playing in Unity, then the OnLeftRoom and OnDisconnected function gets executed . I have highlighed with a red rectangle around it in the screenshot as indicated above.
As per this answer, it is said that the callback OnConnectedToMaster will be executed. I implemented that callback also but nothing inside it is getting printed.Infact I implemented every callback, not is happening
In my game I have to disconnect entirely before connecting again but somehow it is not happening.How do you actually do it?