using UnityEngine;

namespace Obstacle
{
    public class StaticObstacle : MonoBehaviour
    {
        public float despawnDistance = 20f;
    
        private Transform _player;
        private GameObject _originalPrefab;

        public void Init(Transform player, GameObject prefab)
        {
            _player = player;
            _originalPrefab = prefab;
        }

        void Update()
        {
            if (_player != null && transform.position.z < _player.position.z - despawnDistance)
            {
                SimpleObjectPool.Instance.ReturnToPool(_originalPrefab, gameObject);
            }
        }

    }
}