using System.Collections;
using UnityEngine;

public class CatTrashSpawner : MonoBehaviour
{
    public static CatTrashSpawner Instance;

    [SerializeField] private GameObject trashPrefab;

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
    }

    public void SpawnTrashBehind(Transform cat)
    {
        StartCoroutine(SpawnRoutine(cat));
    }

    private IEnumerator SpawnRoutine(Transform cat)
    {
        yield return new WaitForSeconds(5f);

        for (int i = 0; i < 2; i++)
        {
            Vector3 behind = cat.position - cat.right * 0.6f;
            Instantiate(trashPrefab, behind, Quaternion.identity);
            yield return new WaitForSeconds(3.5f);
        }
    }
}