/// <summary> /// Despawn the specified gameObject, placing it back into it's respective pool /// </summary> /// <param name="gameObject">Game object to despawn</param> public static void Despawn(GameObject gameObject) { RFGameObjectPoolMember rpm = gameObject.GetComponent <RFGameObjectPoolMember>(); if (rpm != null) { rpm.objectPool.Despawn(gameObject); } else { GameObject.Destroy(gameObject); } }
/// <summary> /// Despawn the specified gameObject. /// </summary> /// <param name="gameObject">Game object to despawn</param> public void Despawn(GameObject gameObject) { // Make sure the despawned object belongs in THIS pool. RFGameObjectPoolMember rpm = gameObject.GetComponent <RFGameObjectPoolMember>(); if (rpm != null) { if (rpm.objectPool == this) { gameObject.SetActive(false); inactiveObjects.Push(gameObject); } else { // The game object is a member to a different pool. Programmer error in despawn request? Debug.Log("Despawning a gameobject to the wrong OBJECT POOL! Redirecting."); rpm.objectPool.Despawn(gameObject); } } else { GameObject.Destroy(gameObject); } }