Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MatchMaker : Photon.PunBehaviour
- {
- [SerializeField]
- private PhotonLogLevel LogLevel = PhotonLogLevel.Informational;
- [SerializeField]
- private byte MaxPlayersPerRoom = 4;
- private const string gameVersion = "1.0";
- private bool isConnecting;
- private void Awake()
- {
- PhotonNetwork.logLevel = LogLevel;
- PhotonNetwork.automaticallySyncScene = true;
- }
- private void Start()
- {
- Connect();
- }
- public void Connect()
- {
- isConnecting = true;
- PhotonNetwork.ConnectUsingSettings(gameVersion);
- }
- #region Photon.PunBehaviour Callbacks
- public override void OnConnectedToMaster()
- {
- Debug.Log($"{nameof(MatchMaker)}.OnConnectedToMaster() was called by PUN");
- if (isConnecting)
- {
- PhotonNetwork.JoinOrCreateRoom("MyRoom", new RoomOptions() { MaxPlayers = MaxPlayersPerRoom }, null);
- }
- }
- public override void OnLeftRoom()
- {
- isConnecting = false;
- }
- public override void OnConnectionFail(DisconnectCause cause)
- {
- Debug.Log($"Connection failed: {cause}");
- isConnecting = false;
- }
- public override void OnConnectedToPhoton()
- {
- Debug.Log("Connected to Photon");
- }
- public override void OnDisconnectedFromPhoton()
- {
- Debug.Log($"{nameof(MatchMaker)}.OnDisconnectedFromPhoton() was called by PUN");
- }
- public override void OnJoinedRoom()
- {
- Debug.Log($"{nameof(MatchMaker)}.OnJoinedRoom() was called by PUN");
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement