I am building a 2 player multiplayer system where One player creates a room and another player “joins randomly” to a room.
this is my Awake function in the online menu scene.
void Awake()
{
//I have to do this because if player leaves this scene and again enter this scene, he can't join or create any room.
if (PhotonNetwork.connected)
{
PhotonNetwork.Disconnect ();
}
PhotonNetwork.automaticallySyncScene = true;
if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
{
PhotonNetwork.ConnectUsingSettings ("0.9");
}
if (string.IsNullOrEmpty (PhotonNetwork.playerName))
{
PhotonNetwork.playerName = Guest"+Random.Range(101, 10000);
}
}
void FixedUpdate()
{
if (!PhotonNetwork.connected) {
if (PhotonNetwork.connecting) {
connectionStatus.text = "Connecting to server...";
}
}
}
Now I firstly tried JoinRandomRoom(), if it fails i.e. inside OnPhotonRandomJoinFailed() function, a room will be created by the player and he will wait for player. Now, my problem is, if two players try to join a room and if they fails and one of them “Go Back” to “Main Menu”, other one automatically goes to that scene. Even if the room joining is failed.
I make PhotonNetwork.automaticallySyncScene = false, in the “Go Back” button’s action method. But still it’s not working properly.
The most ridiculous scenario is: After coming back to “Main Menu” scene, I can’t go to the “Online Menu Scene” again. I have to clear the App Data from mobile settings, then it works. One thing is, user have to login with Facebook/Google.
Please help me someone. and ignore any syntax error in the code.