I have followed the Photon PU Tutorial carefully following each step, but after I declare the bool isConnecting and surround the PhotonNetwork.JoinRandomRoom(); I receive this error everytime I try to start a server using unity this error appears
If someone could help me I would be really grateful
here is my entire launcher c# script(just as the tutorial one):
JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: ConnectingToNameServer). Wait for callback: OnJoinedLobby or OnConnectedToMaster. UnityEngine.Debug:LogError(Object) Photon.Pun.PhotonNetwork:JoinRandomRoom(Hashtable, Byte, MatchmakingMode, TypedLobby, String, String[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1588) Photon.Pun.PhotonNetwork:JoinRandomRoom() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1522) Com.MyCompany.MyGame.Launcher:Connect() (at Assets/Photon/PhotonUnityNetworking/Demos/PunBasics-Tutorial/Scripts/Launcher.cs:93) UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.3.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
If someone could help me I would be really grateful
here is my entire launcher c# script(just as the tutorial one):
using UnityEngine; using Photon.Pun; using Photon.Realtime; namespace Com.MyCompany.MyGame { public class Launcher : MonoBehaviourPunCallbacks { /// <summary> /// The maximum number of players per room. When a room is full, it can't be joined by new players, and so new room will be created. /// </summary> [Tooltip("The maximum number of players per room. When a room is full, it can't be joined by new players, and so new room will be created")] [SerializeField] private byte maxPlayersPerRoom = 4; #region Public Fields [Tooltip("The Ui Panel to let the user enter name, connect and play")] [SerializeField] private GameObject controlPanel; [Tooltip("The UI Label to inform the user that the connection is in progress")] [SerializeField] private GameObject progressLabel; #endregion #region Private Serializable Fields #endregion #region Private Fields bool isConnecting; /// <summary> /// This client's version number. Users are separated from each other by gameVersion (which allows you to make breaking changes). /// </summary> string gameVersion = "1"; #endregion #region MonoBehaviour CallBacks /// <summary> /// MonoBehaviour method called on GameObject by Unity during early initialization phase. /// </summary> void Awake() { // #Critical // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically PhotonNetwork.AutomaticallySyncScene = true; } /// <summary> /// MonoBehaviour method called on GameObject by Unity during initialization phase. /// </summary> void Start() { progressLabel.SetActive(false); controlPanel.SetActive(true); } #endregion #region Public Methods /// <summary> /// Start the connection process. /// - If already connected, we attempt joining a random room /// - if not yet connected, Connect this application instance to Photon Cloud Network /// </summary> public void Connect() { // keep track of the will to join a room, because when we come back from the game we will get a callback that we are connected, so we need to know what to do then isConnecting = PhotonNetwork.ConnectUsingSettings(); progressLabel.SetActive(true); controlPanel.SetActive(false); // we check if we are connected or not, we join if we are , else we initiate the connection to the server. if (PhotonNetwork.IsConnected) { // #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one. PhotonNetwork.JoinRandomRoom(); } else { // #Critical, we must first and foremost connect to Photon Online Server. PhotonNetwork.ConnectUsingSettings(); PhotonNetwork.GameVersion = gameVersion; } } #endregion #region MonoBehaviourPunCallbacks Callbacks public override void OnConnectedToMaster() { if (isConnecting) { // #Critical: The first we try to do is to join a potential existing room. If there is, good, else, we'll be called back with OnJoinRandomFailed() PhotonNetwork.JoinRandomRoom(); isConnecting = false; } } public override void OnDisconnected(DisconnectCause cause) { progressLabel.SetActive(false); controlPanel.SetActive(true); Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause); } public override void OnJoinRandomFailed(short returnCode, string message) { Debug.Log("PUN Basics Tutorial/Launcher:OnJoinRandomFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom"); // #Critical: we failed to join a random room, maybe none exists or they are all full. No worries, we create a new room. PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom }); } public override void OnJoinedRoom() { Debug.Log("PUN Basics Tutorial/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room."); if (PhotonNetwork.CurrentRoom.PlayerCount == 1) { Debug.Log("We load the 'Room for 1' "); // #Critical // Load the Room Level. PhotonNetwork.LoadLevel("Room for 1"); } } } #endregion }