using System;
using UnityEngine;
using UnityEngine.Pool;

namespace Patterns_And_Principles.Patterns.Object_Pool_Pattern.UnityObjectPool.Script
{
    public class Bullet : MonoBehaviour
    {
        [SerializeField]
        private float speed;
        private IObjectPool<Bullet> bulletPool;

        private void OnBecameInvisible()
        {
            bulletPool.Release(this);
        }

        private void Update()
        {
            gameObject.transform.Translate(Vector3.right * speed * Time.deltaTime);
        }

        public void SetPool(IObjectPool<Bullet> _bulletPool)
        {
            bulletPool = _bulletPool;
        }
    }
}