// Update is called once per frame void Update() { if (lifeTime >= maxLifeTime) { poolableComponent.AddToPool(); } lifeTime += Time.deltaTime; }
private void Update() { if (timer > lifeTime) { poolableComponent.AddToPool(); timer = 0; } timer += Time.deltaTime; }
private void OnTriggerEnter2D(Collider2D collision) { if (poolableComponent) { poolableComponent.AddToPool(); } else { Debug.Log($"{this.gameObject.name} is not a poolable object. -[DestroyComponent]"); Destroy(this.gameObject); } }
public void Die() { // if the object has poolableComponent it should go to the pool otherwise destroy it. PoolableComponent poolableComponent = this.gameObject.GetComponent <PoolableComponent>(); if (poolableComponent) { poolableComponent.AddToPool(); } else { Destroy(this.gameObject); } // would you like to do anything when the object disappeard? (Animation, UI change, ...) onDie?.Invoke(); }