Can't Connect To Room
working on a PUN game in Unity trying to fix matchmaking. It can connect to the server, but I'm having trouble getting two games to connect in a room. Here's the networking code:
Any help would be great.
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using Hashtable = ExitGames.Client.Photon.Hashtable; public class Network : MonoBehaviourPunCallbacks { public static Network instance; private bool connected; private bool ready; private bool finding; private bool joined; private bool createRoomExecuted; private bool loadRoomExecuted; private byte maxPlayers = 2; public static string matchKey; public const string MATCH_KEY = "mk"; private void Awake() { if(instance != null && instance != this) { instance.gameObject.SetActive(false); Destroy(instance.gameObject); } instance = this; finding = false; joined = false; } void Start() { PhotonNetwork.SendRate = 30; PhotonNetwork.SerializationRate = 10; PhotonNetwork.GameVersion = "0.2.3"; if (!PhotonNetwork.IsConnected) PhotonNetwork.ConnectUsingSettings(); SetProperties(); } public override void OnConnectedToMaster() { print("connected to master server"); connected = true; PhotonNetwork.JoinLobby(TypedLobby.Default); } public override void OnDisconnected(DisconnectCause cause) { print("Discconnected from server for reason: " + cause.ToString()); } public void QuickMatch() { finding = true; } public override void OnJoinedLobby() { if (!PhotonNetwork.InRoom) { ready = true; } } void Update() { if (finding) { if (connected && joined) { if (!createRoomExecuted) { ExitGames.Client.Photon.Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable { { MATCH_KEY, matchKey } }; OpJoinRandomRoomParams opJoinRandomRoomParams = new OpJoinRandomRoomParams(); opJoinRandomRoomParams.ExpectedMaxPlayers = maxPlayers; opJoinRandomRoomParams.ExpectedCustomRoomProperties = expectedCustomRoomProperties; PhotonNetwork.JoinRandomRoom(); createRoomExecuted = true; } } } if (joined) { if(PhotonNetwork.CurrentRoom.PlayerCount == 2) { if (!loadRoomExecuted) { //Load Room finding = false; loadRoomExecuted = true; } } } } public void CancelButton() { finding = false; } public override void OnJoinRandomFailed(short returnCode, string message) { CreateRoom(); } private void CreateRoom() { string[] keys = { MATCH_KEY }; RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = maxPlayers; roomOptions.CustomRoomPropertiesForLobby = keys; roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable { { MATCH_KEY, matchKey } }; PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default); print("Created a Room"); } public override void OnJoinedRoom() { joined = true; } public static void SetProperties() { int.TryParse(SerializationManager.Load("level"), out int level); int.TryParse(SerializationManager.Load("xp"), out int xp); if(level == 1 || level == 2) { if (xp == 100) { matchKey = "A"; } else if (xp <= 100) { matchKey = "B"; } } else if (level == 3 || level == 4) { if (xp >= 500) { matchKey = "B"; } else if (xp <= 500) { matchKey = "C"; } } else if (level == 5 || level == 6) { if(xp >= 800) { matchKey = "D"; } else if(xp <= 800) { matchKey = "E"; } } else if(level == 7 || level == 9) { if (xp >= 1000) { matchKey = "F"; } else if (xp <= 1000) { matchKey = "G"; } } else if(level == 10 || level == 11) { if (xp >= 1200) { matchKey = "H"; } else if (xp <= 1200) { matchKey = "I"; } } else if(level == 12 || level == 13) { if (xp >= 1500) { matchKey = "J"; } else if (xp <= 1500) { matchKey = "K"; } } else if(level == 14 || level == 15) { if (xp >= 2300) { matchKey = "L"; } else if (xp <= 2300) { matchKey = "M"; } } else if(level == 16 || level == 17) { if (xp >= 2750) { matchKey = "N"; } else if (xp <= 2750) { matchKey = "O"; } } else if(level == 18 || level == 19) { if (xp >= 3200) { matchKey = "P"; } else if (xp <= 3200) { matchKey = "Q"; } } else if(level == 20 || level == 21) { if (xp >= 3750) { matchKey = "R"; } else if (xp <= 3750) { matchKey = "S"; } } else if(level == 22 || level == 23) { if (xp >= 4100) { matchKey = "T"; } else if (xp <= 4100) { matchKey = "U"; } } else if(level == 24 || level == 25) { if (xp >= 4500) { matchKey = "V"; } else if (xp <= 4500) { matchKey = "W"; } } else { matchKey = "X"; } } }
Any help would be great.
0
Answers
-
Matchmaking is explained nicely in the Matchmaking doc.
We can't check your code, sorry. I am tempted to just remove it, if you don't mind.0