Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Handles client connection and disconnection events.
- /// </summary>
- /// <param name="networkConnection">The network connection of the client.</param>
- /// <param name="args">Arguments containing information about the connection state.</param>
- private void OnClientConnect(NetworkConnection networkConnection, RemoteConnectionStateArgs args)
- {
- Debug.Log("Client Connected...attempting to load client into last connected scene");
- if (args.ConnectionState == RemoteConnectionState.Started)
- {
- LoadSceneOnClient("SampleScene", networkConnection);
- }
- if (args.ConnectionState == RemoteConnectionState.Stopped)
- {
- Debug.Log("Client Disconnected");
- }
- }
- /// <summary>
- /// Loads a scene on the client.
- /// </summary>
- /// <param name="sceneName">The name of the scene to load.</param>
- /// <param name="connection">The network connection of the client.</param>
- public void LoadSceneOnClient(string sceneName, NetworkConnection connection)
- {
- SceneLoadData sceneLoadData = new SceneLoadData(sceneName);
- sceneLoadData.ReplaceScenes = ReplaceOption.None;
- sceneLoadData.PreferredActiveScene = new PreferredScene(SceneLookupData.CreateData(sceneName));
- networkManager.SceneManager.LoadConnectionScenes(connection, sceneLoadData);
- }
Advertisement
Add Comment
Please, Sign In to add comment