Blipples

GameManage Client Connection Not Firing Off OnRemoteConnectionState Event

May 15th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public class GameManager : MonoBehaviour
  2. {
  3. void Play()
  4. {
  5. currentGameState = GameState.Play;
  6.  
  7. if (currentGameMode == GameMode.SinglePlayer)
  8. {
  9. networkManager.ServerManager.StartConnection();
  10.  
  11. Debug.Log("Playing Singleplayer!");
  12. }
  13.  
  14. if (currentGameMode == GameMode.MultiPlayer)
  15. {
  16. if (currentNetworkState == NetworkState.Host)
  17. {
  18. networkManager.ServerManager.StartConnection();
  19. }
  20.  
  21. Debug.Log("Playing Multiplayer!");
  22. }
  23.  
  24. networkManager.ClientManager.StartConnection();
  25. }
  26. }
  27.  
  28. public class SceneLoader : MonoBehaviour
  29. {
  30. void Awake()
  31. {
  32. instance = this;
  33.  
  34. networkManager = InstanceFinder.NetworkManager;
  35.  
  36. InstanceFinder.SceneManager.OnLoadEnd += RegisterScene;
  37. InstanceFinder.SceneManager.OnUnloadEnd += UnregisterScene;
  38.  
  39. InstanceFinder.ServerManager.OnRemoteConnectionState += OnClientConnect;
  40. }
  41.  
  42. private void OnClientConnect(NetworkConnection networkConnection, RemoteConnectionStateArgs args)
  43. {
  44. Debug.Log("Client Connected...attempting to load client into last connected scene");
  45.  
  46. if (args.ConnectionState == RemoteConnectionState.Started)
  47. {
  48. LoadSceneOnClient("SampleScene", networkConnection);
  49. }
  50.  
  51. if (args.ConnectionState == RemoteConnectionState.Stopped)
  52. {
  53. Debug.Log("Client Disconnected");
  54. }
  55.  
  56. }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment