Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Не влезло в вопрос . Вот тут код)
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- using Photon.Realtime;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class ConnectToServer : MonoBehaviourPunCallbacks
- {
- public Slider loadingBar;
- void Start()
- {
- if (!PhotonNetwork.IsConnected)
- {
- UnityEngine.Debug.Log("Attempting to connect to Photon server...");
- PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "eu";
- PhotonNetwork.ConnectUsingSettings();
- }
- else
- {
- UnityEngine.Debug.LogWarning("Already connected to Photon server.");
- }
- }
- void Update()
- {
- if (loadingBar != null)
- {
- if (PhotonNetwork.IsConnectedAndReady)
- {
- loadingBar.value = 1f;
- UnityEngine.Debug.Log("Connected and ready!");
- }
- else if (PhotonNetwork.IsConnected)
- {
- loadingBar.value = 0.5f;
- UnityEngine.Debug.Log("Connected but not ready. Ping: " + PhotonNetwork.GetPing());
- }
- else
- {
- loadingBar.value = 0f;
- UnityEngine.Debug.Log("Not connected.");
- }
- }
- }
- public override void OnConnectedToMaster()
- {
- UnityEngine.Debug.Log("Connected to Master. Loading MainMenu scene...");
- if (SceneManager.GetSceneByName("MainMenu") != null)
- {
- UnityEngine.Debug.Log("MainMenu scene found, loading...");
- SceneManager.LoadScene("MainMenu");
- }
- else
- {
- UnityEngine.Debug.LogError("MainMenu scene not found!");
- }
- }
- public override void OnDisconnected(DisconnectCause cause)
- {
- UnityEngine.Debug.LogError($"Disconnected from Photon server: {cause}");
- switch (cause)
- {
- case DisconnectCause.Exception:
- UnityEngine.Debug.LogError("Exception error occurred.");
- break;
- case DisconnectCause.ServerTimeout:
- UnityEngine.Debug.LogError("Server timeout.");
- break;
- case DisconnectCause.ClientTimeout:
- UnityEngine.Debug.LogError("Client timeout.");
- break;
- case DisconnectCause.InvalidAuthentication:
- UnityEngine.Debug.LogError("Invalid authentication.");
- break;
- case DisconnectCause.MaxCcuReached:
- UnityEngine.Debug.LogError("Max CCU reached.");
- break;
- case DisconnectCause.DisconnectByServerLogic:
- UnityEngine.Debug.LogError("Disconnected by server logic.");
- break;
- case DisconnectCause.DisconnectByClientLogic:
- UnityEngine.Debug.LogError("Disconnected by client logic.");
- break;
- case DisconnectCause.InvalidRegion:
- UnityEngine.Debug.LogError("Invalid region.");
- break;
- case DisconnectCause.OperationNotAllowedInCurrentState:
- UnityEngine.Debug.LogError("Operation not allowed in current state.");
- break;
- default:
- UnityEngine.Debug.LogError("Disconnected for an unknown reason.");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement