Hello, I am using a code that is based on join or create a room (PUN2). At the moment of the game, the player enters a room and is looking for a player (and in the other game window), he is still looking for an opponent, even though both players are in the rooms.
It seems to me that the problem is that the player is not sending information about presence in the room, but how can I fix this?
using Photon.Pun;
using Photon.Pun.Demo.Cockpit;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class GlobalMenu : MonoBehaviourPunCallbacks
{
[SerializeField] private GameObject findOpponentPanel = null;
[SerializeField] private GameObject waitingStatusPanel = null;
[SerializeField] private TextMeshProUGUI waitingStatusText= null;
private bool isConnecting = false;
private const string GameVersion = "1.6";
private const int maxPlayersPerRoom = 2;
private void Awake() => PhotonNetwork.AutomaticallySyncScene = true;
public void FindOpponent()
{
isConnecting = true;
findOpponentPanel.SetActive(true);
waitingStatusPanel.SetActive(true);
waitingStatusText.text = "Searching ...";
if(PhotonNetwork.IsConnected)
{
PhotonNetwork.JoinRandomRoom();
}
else
{
PhotonNetwork.GameVersion = GameVersion;
PhotonNetwork.ConnectUsingSettings();
}
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected To Master");
if(isConnecting)
{
PhotonNetwork.JoinRandomRoom();
}
}
public override void OnDisconnected(DisconnectCause cause)
{
waitingStatusPanel.SetActive(false);
findOpponentPanel.SetActive(true);
Debug.Log($"Disconnect due to: {cause}");
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("No clients are waiting for an opponent, creating new room");
PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom }, null);
}
public override void OnJoinedRoom()
{
Debug.Log("Client successfully joined a room");
int playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
if (playerCount != maxPlayersPerRoom)
{
waitingStatusText.text = "Wainting For Opponent";
Debug.Log("Client is waiting for an opponent");
}
else
{
waitingStatusText.text = "Opponent Found";
Debug.Log("Matching is ready to begin");
}
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
if(PhotonNetwork.CurrentRoom.PlayerCount == maxPlayersPerRoom)
{
PhotonNetwork.CurrentRoom.IsOpen = false;
Debug.Log("Match is ready to begin");
waitingStatusText.text = "Opponent Found";
Debug.Log("Match is ready begin");
PhotonNetwork.LoadLevel("Arena");
}
}
}