void OnEnable() { instance = Instantiate(this, barPrefab, canvas, worldCamera, attachPoint, networkInstantiate, networkGroup); if (instance != null) { instance.gameObject.SetActive(true); } }
public static EnergyBarUGUIBase Instantiate(Object parent, EnergyBarUGUIBase barPrefab, ObjectFinder canvasFinder, ObjectFinder cameraFinder, Transform attachPoint, bool networkInstantiate, int networkGroup) { EnergyBarUGUIBase bar; #if !(UNITY_FLASH || UNITY_NACL || UNITY_METRO || UNITY_WP8 || UNITY_WEBGL) if (networkInstantiate) { bar = Network.Instantiate(barPrefab, barPrefab.transform.position, barPrefab.transform.rotation, networkGroup) as EnergyBarUGUIBase; } else { bar = Instantiate(barPrefab) as EnergyBarUGUIBase; } #else bar = Instantiate(barPrefab) as EnergyBarUGUIBase; #endif if (canvasFinder.chosenMethod == ObjectFinder.Method.ByType) { bar.transform.SetParent((canvasFinder.Lookup<Canvas>(parent)).transform, true); } else { bar.transform.SetParent((canvasFinder.Lookup<Transform>(parent)), true); } var followObject = bar.GetComponent<EnergyBarFollowObject>(); if (followObject == null) { followObject = bar.gameObject.AddComponent<EnergyBarFollowObject>(); } followObject.worldCamera = cameraFinder; followObject.followObject = attachPoint.gameObject; return bar; }