Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameManager : MonoBehaviour
- {
- void Play()
- {
- currentGameState = GameState.Play;
- if (currentGameMode == GameMode.SinglePlayer)
- {
- networkManager.ServerManager.StartConnection();
- Debug.Log("Playing Singleplayer!");
- }
- if (currentGameMode == GameMode.MultiPlayer)
- {
- if (currentNetworkState == NetworkState.Host)
- {
- networkManager.ServerManager.StartConnection();
- }
- Debug.Log("Playing Multiplayer!");
- }
- networkManager.ClientManager.StartConnection();
- }
- }
- public class SceneLoader : MonoBehaviour
- {
- void Awake()
- {
- instance = this;
- networkManager = InstanceFinder.NetworkManager;
- InstanceFinder.SceneManager.OnLoadEnd += RegisterScene;
- InstanceFinder.SceneManager.OnUnloadEnd += UnregisterScene;
- InstanceFinder.ServerManager.OnRemoteConnectionState += OnClientConnect;
- }
- 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");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment