Blipples

Untitled

Jan 5th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | Gaming | 0 0
  1.  
  2.     /// <summary>
  3.     /// Handles client connection and disconnection events.
  4.     /// </summary>
  5.     /// <param name="networkConnection">The network connection of the client.</param>
  6.     /// <param name="args">Arguments containing information about the connection state.</param>
  7.     private void OnClientConnect(NetworkConnection networkConnection, RemoteConnectionStateArgs args)
  8.     {
  9.         Debug.Log("Client Connected...attempting to load client into last connected scene");
  10.  
  11.         if (args.ConnectionState == RemoteConnectionState.Started)
  12.         {
  13.             LoadSceneOnClient("SampleScene", networkConnection);
  14.         }
  15.  
  16.         if (args.ConnectionState == RemoteConnectionState.Stopped)
  17.         {            
  18.             Debug.Log("Client Disconnected");
  19.         }
  20.     }
  21.  
  22.     /// <summary>
  23.     /// Loads a scene on the client.
  24.     /// </summary>
  25.     /// <param name="sceneName">The name of the scene to load.</param>
  26.     /// <param name="connection">The network connection of the client.</param>
  27.     public void LoadSceneOnClient(string sceneName, NetworkConnection connection)
  28.     {
  29.         SceneLoadData sceneLoadData = new SceneLoadData(sceneName);
  30.         sceneLoadData.ReplaceScenes = ReplaceOption.None;
  31.         sceneLoadData.PreferredActiveScene = new PreferredScene(SceneLookupData.CreateData(sceneName));
  32.         networkManager.SceneManager.LoadConnectionScenes(connection, sceneLoadData);
  33.     }
  34.    
  35.  
Advertisement
Add Comment
Please, Sign In to add comment