private FloatingHealth OnCreateFloatingHealth() { FloatingHealth floating = GameObject.Instantiate <FloatingHealth>(floatingHealth); floating.transform.SetParent(rootTrans, false); floating.Init(canvas, mirrorVector, redNumbers, greenNumbers, purpleNumbers); return(floating); }
// When you no longer use this item Call it public void RemoveFloatingHealth(FloatingHealth bar) { if (bar == null) { return; } bar.gameObject.SetActive(false); floatingHealthPool.DisposeObject(bar); }
// Use this for initialization void Start() { healthBar = GameResourceLoadManager.GetInstance().LoadAsset <HealthBar>("HealthBar"); healthBar.transform.localScale = Vector3.one; healthBar.transform.localPosition = Vector3.zero; healthBar.transform.localRotation = Quaternion.identity; floatingHealth = GameResourceLoadManager.GetInstance().LoadAsset <FloatingHealth>("FloatingHealth"); floatingHealth.transform.localScale = Vector3.one; floatingHealth.transform.localPosition = Vector3.zero; floatingHealth.transform.localRotation = Quaternion.identity; healthBarPool = new ObjectPool <HealthBar>(OnCreateHealthBar, OnCleanHealthBar); floatingHealthPool = new ObjectPool <FloatingHealth>(OnCreateFloatingHealth, OnCleanFloatingHealth); }
void OnDestroy() { healthBar = null; floatingHealth = null; if (healthBarPool != null) { healthBarPool.Clear(); healthBarPool = null; } if (floatingHealthPool != null) { floatingHealthPool.Clear(); floatingHealthPool = null; } }
private void OnCleanFloatingHealth(FloatingHealth bar) { GameObject.Destroy(bar.gameObject); bar = null; }