using UnityEngine;

public class PipeSpawner : MonoBehaviour
{
    [SerializeField] private GameObject pipe;
    [SerializeField] private float heightRange = 3f;
    [SerializeField] private float spawnTimeLimit = 1.5f;
    private float _timer = 0;
    
    void Start()
    {
        PipeSpawnerMethod();
    }

    void Update()
    {
        if (_timer > spawnTimeLimit)
        {
            _timer = 0;
            PipeSpawnerMethod();
        }
        _timer += Time.deltaTime;
    }

    void PipeSpawnerMethod()
    {
        Vector3 pipePosition = new  Vector3(transform.position.x, Random.Range(-heightRange, heightRange), 0);
        GameObject _pipe = Instantiate(pipe, pipePosition, Quaternion.identity);
        
        Destroy(_pipe, 5f);
    }
}
