// Use this for initialization void JoinLobby() { PUN_NetworkManager nm = GameObject.FindObjectOfType <PUN_NetworkManager>(); nm.SetPlayerName(_playerName); nm.Connect(); }
private void Awake() { if (nm == null) { nm = this; DontDestroyOnLoad(this.gameObject); this.gameObject.name = gameObject.name + " Instance"; } else { Destroy(this.gameObject); return; } PhotonNetwork.AutomaticallySyncScene = _syncScenes; //Automatically load scenes together (make sure everyone is always on the same scene) }
private static void M_NetworkManager() { if (!FindObjectOfType <PUN_NetworkManager>()) { GameObject _networkManager = new GameObject("NetworkManager"); _networkManager.AddComponent <PUN_NetworkManager>(); _networkManager.AddComponent <PUN_LobbyUI>(); _networkManager.AddComponent <PUN_NetworkManager>()._spawnPoint = _networkManager.transform; } else { PUN_NetworkManager _networkManager = FindObjectOfType <PUN_NetworkManager>(); _networkManager._spawnPoint = _networkManager.gameObject.transform; } }
void MakeAndAssignPrefab(GameObject prefab) { try { //Create the Prefab if (!Directory.Exists("Assets/Resources")) { //if it doesn't, create it Directory.CreateDirectory("Assets/Resources"); } if (AssetDatabase.LoadAssetAtPath("Assets/Resources/" + prefab.name + ".prefab", typeof(GameObject))) { if (EditorUtility.DisplayDialog("Are you sure?", "The prefab already exists. Do you want to overwrite it?", "Yes", "No")) //If the user presses the yes button, create the Prefab { CreatePrefab(prefab, "Assets/Resources/" + prefab.name + ".prefab"); } //If the name doesn't exist, create the new Prefab else { Debug.Log("The prefab for this gameobject \"" + prefab.name + "\" was not made. Make one manually and assign that prefab to the \"_playerPrefab\" on the NetworkManager gameobject."); } } else { CreatePrefab(prefab, "Assets/Resources/" + prefab.name + ".prefab"); } //Application.dataPath M_NetworkManager(); PUN_NetworkManager nm = FindObjectOfType <PUN_NetworkManager>(); nm._playerPrefab = (GameObject)Resources.Load(prefab.name); } catch (Exception e) { Debug.Log("An error occured. Make sure the prefab was made and that prefab gets assigned to the \"NetworkManager\""); Debug.LogError(e); } }
public void Start() { nm = FindObjectOfType <PUN_NetworkManager>(); }