Advertisement
Guest User

Untitled

a guest
Aug 8th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | Source Code | 0 0
  1. Не влезло в вопрос . Вот тут код)
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Photon.Pun;
  6. using Photon.Realtime;
  7. using UnityEngine.SceneManagement;
  8. using UnityEngine.UI;
  9.  
  10. public class ConnectToServer : MonoBehaviourPunCallbacks
  11. {
  12. public Slider loadingBar;
  13.  
  14. void Start()
  15. {
  16. if (!PhotonNetwork.IsConnected)
  17. {
  18. UnityEngine.Debug.Log("Attempting to connect to Photon server...");
  19. PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "eu";
  20. PhotonNetwork.ConnectUsingSettings();
  21. }
  22. else
  23. {
  24. UnityEngine.Debug.LogWarning("Already connected to Photon server.");
  25. }
  26. }
  27.  
  28. void Update()
  29. {
  30. if (loadingBar != null)
  31. {
  32. if (PhotonNetwork.IsConnectedAndReady)
  33. {
  34. loadingBar.value = 1f;
  35. UnityEngine.Debug.Log("Connected and ready!");
  36. }
  37. else if (PhotonNetwork.IsConnected)
  38. {
  39. loadingBar.value = 0.5f;
  40. UnityEngine.Debug.Log("Connected but not ready. Ping: " + PhotonNetwork.GetPing());
  41. }
  42. else
  43. {
  44. loadingBar.value = 0f;
  45. UnityEngine.Debug.Log("Not connected.");
  46. }
  47. }
  48. }
  49.  
  50. public override void OnConnectedToMaster()
  51. {
  52. UnityEngine.Debug.Log("Connected to Master. Loading MainMenu scene...");
  53. if (SceneManager.GetSceneByName("MainMenu") != null)
  54. {
  55. UnityEngine.Debug.Log("MainMenu scene found, loading...");
  56. SceneManager.LoadScene("MainMenu");
  57. }
  58. else
  59. {
  60. UnityEngine.Debug.LogError("MainMenu scene not found!");
  61. }
  62. }
  63.  
  64. public override void OnDisconnected(DisconnectCause cause)
  65. {
  66. UnityEngine.Debug.LogError($"Disconnected from Photon server: {cause}");
  67.  
  68. switch (cause)
  69. {
  70. case DisconnectCause.Exception:
  71. UnityEngine.Debug.LogError("Exception error occurred.");
  72. break;
  73. case DisconnectCause.ServerTimeout:
  74. UnityEngine.Debug.LogError("Server timeout.");
  75. break;
  76. case DisconnectCause.ClientTimeout:
  77. UnityEngine.Debug.LogError("Client timeout.");
  78. break;
  79. case DisconnectCause.InvalidAuthentication:
  80. UnityEngine.Debug.LogError("Invalid authentication.");
  81. break;
  82. case DisconnectCause.MaxCcuReached:
  83. UnityEngine.Debug.LogError("Max CCU reached.");
  84. break;
  85. case DisconnectCause.DisconnectByServerLogic:
  86. UnityEngine.Debug.LogError("Disconnected by server logic.");
  87. break;
  88. case DisconnectCause.DisconnectByClientLogic:
  89. UnityEngine.Debug.LogError("Disconnected by client logic.");
  90. break;
  91. case DisconnectCause.InvalidRegion:
  92. UnityEngine.Debug.LogError("Invalid region.");
  93. break;
  94. case DisconnectCause.OperationNotAllowedInCurrentState:
  95. UnityEngine.Debug.LogError("Operation not allowed in current state.");
  96. break;
  97. default:
  98. UnityEngine.Debug.LogError("Disconnected for an unknown reason.");
  99. break;
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement