Last active
February 20, 2017 04:53
-
-
Save arun02139/54dd8b57bd72bda3d878374ee7fb1ce9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Networking; | |
using UnityEngine.SceneManagement; | |
using UnityEngine.Assertions; | |
using System.Collections; | |
public class LocalHostBootstrap : MonoBehaviour | |
{ | |
string _debugString; | |
void Awake() | |
{ | |
SceneManager.sceneLoaded += OnSceneLoaded; | |
} | |
void OnDestroy() | |
{ | |
SceneManager.sceneLoaded -= OnSceneLoaded; | |
} | |
void OnSceneLoaded(Scene scene, LoadSceneMode mode) | |
{ | |
if (scene.name == "battle") | |
{ | |
if (NetworkManager.singleton == null) | |
StartCoroutine(PauseAndSpawnNetwork()); | |
} | |
} | |
IEnumerator PauseAndSpawnNetwork() | |
{ | |
yield return new WaitForEndOfFrame(); | |
var networkManagerGO = Util.InstantiateFromResource ("SimpleNetwork"); | |
NetworkManager networkManager = networkManagerGO.GetComponent<NetworkManager> (); | |
networkManager.onlineScene = SceneManager.GetActiveScene().name; | |
networkManager.StartHost (); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment