I scripted a code like below.
I can create a room and can tested it with myself when i opened the game twice and everything is ok.
But if a friend create the game or joined my game . it works a few second for us both and then after different amount of seconds he kicked out everytime of the gameroom with the Operation Response 252 and sometimes 252+ 253.
Need help with this.
Launcher Code
Room Script
I can create a room and can tested it with myself when i opened the game twice and everything is ok.
But if a friend create the game or joined my game . it works a few second for us both and then after different amount of seconds he kicked out everytime of the gameroom with the Operation Response 252 and sometimes 252+ 253.
Need help with this.
Launcher Code
public class LauncherMaster : MonoBehaviourPunCallbacks {// MasterScript for Menu public static LauncherMaster Instance; [SerializeField] private string versionName = "0.1"; [Header("UIs")] [SerializeField] GameObject connectingUI; [SerializeField] GameObject usernameUI; public GameObject mainMenuUI; [SerializeField] FindRoomsUI lobbyUI; [SerializeField] GameObject errorUI; [Header("Inputs")] [SerializeField] TMP_InputField usernameInput; [SerializeField] TMP_InputField createGameInput; [SerializeField] TMP_InputField joinGameInput; [Header("Buttons")] [SerializeField] TMP_Text errorText; [SerializeField] TMP_Text nickNameText; [SerializeField] GameObject startButton; [SerializeField] Toggle togglePublic; private void Awake() { Instance = this; connectingUI.SetActive(true); PhotonNetwork.ConnectUsingSettings(); Debug.Log("Connecting..."); } public override void OnConnectedToMaster() { PhotonNetwork.JoinLobby(); Debug.Log("Connected"); } public override void OnJoinedLobby() { connectingUI.SetActive(false); // wenn nickname schon vorhanden //usernameUI.SetActive(false); usernameUI.SetActive(true); mainMenuUI.SetActive(true); Debug.Log("Joined Lobby"); } public void ChangeUserNameInput() { if(usernameInput.text.Length >=4) { startButton.SetActive(true); } else { startButton.SetActive(false); } } public void SetUserName() { usernameUI.SetActive(false); //PhotonNetwork.playerName = usernameInput.text; PhotonNetwork.NickName = usernameInput.text; nickNameText.text = "Nickname: " + PhotonNetwork.NickName; } public void CreateGame() { if (string.IsNullOrEmpty(createGameInput.text)) { Debug.Log("Type a roomName"); return; } if(togglePublic.isOn) { RoomOptions roomOptions = new RoomOptions() { MaxPlayers = 10 }; } if (!PhotonNetwork.IsMasterClient) { Debug.LogError("PhotonNetwork : Trying to Load a level but we are not the master Client"); } if (togglePublic.isOn) { if (PhotonNetwork.CreateRoom(createGameInput.text, new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 10 }, null)) { connectingUI.SetActive(true); print("Creating room successfully send"); } else { print("Creating room failed to send"); } ; } else { if (PhotonNetwork.CreateRoom(createGameInput.text, new RoomOptions() { IsVisible = false, IsOpen = true, MaxPlayers = 10 }, null)) { connectingUI.SetActive(true); print("Creating room successfully send"); } else { print("Creating room failed to send"); } } ; } public override void OnJoinedRoom() //if joined or create { PhotonNetwork.AutomaticallySyncScene = true; if (PhotonNetwork.IsMasterClient) { PhotonNetwork.LoadLevel("Arena"); } // print("Room created successfully"); } public override void OnJoinRoomFailed(short returnCode, string message) { Debug.Log("Roomname doesn´t exsist"); } public override void OnCreateRoomFailed(short returnCode, string message) { print("create room failed " + message); errorUI.SetActive(true); errorText.text = "Room creation failed " + message; } public void JoinRoom() { RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = 10; PhotonNetwork.JoinRoom(joinGameInput.text); connectingUI.SetActive(true); PhotonNetwork.AutomaticallySyncScene = true; } [b] public void JoinRoomInfo(RoomInfo info) { RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = 10; PhotonNetwork.JoinRoom(info.Name); connectingUI.SetActive(true); PhotonNetwork.AutomaticallySyncScene = true; }[/b] public void QuitGame() { Application.Quit(); } }
Room Script
public class RoomManager : MonoBehaviourPunCallbacks {//Check the right Scene public static RoomManager Instance; public PlayerManager playerManager; private void Awake() { if(Instance) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); Instance = this; } public override void OnEnable() { base.OnEnable(); SceneManager.sceneLoaded += OnSceneLoaded; } public override void OnDisable() { base.OnDisable(); SceneManager.sceneLoaded -= OnSceneLoaded; } void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { if(scene.buildIndex == 1) //We´re in the game scene { playerManager = PhotonNetwork.Instantiate("PlayerManager", Vector3.zero, Quaternion.identity).GetComponent<PlayerManager>(); RoomUI roomUI = FindObjectOfType<RoomUI>(); roomUI.player1StartButton.GetComponent<Button>().onClick.AddListener(playerManager.SpawnPlayer1); roomUI.player2StartButton.GetComponent<Button>().onClick.AddListener(playerManager.SpawnPlayer2); } } public override void OnDisconnected(DisconnectCause cause) { Debug.LogWarningFormat("Launcher: OnDisconnected() was called by PUN with reason {0}", cause); } }