using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DynamicsSpawner : MonoBehaviour {
    [SerializeField] private List<GameObject> Dynamics;
    [SerializeField] private Transform parent;
    [SerializeField] private float max = 2f;
    [SerializeField] private float min = 1f;

    private float timer;

    private void Start() {
        timer = Random.Range(min, max);
    }

    private void Update() {
        if (GameManager.Instance.IsRunning) {
            timer -= Time.deltaTime;

            if (timer <= 0) {
                timer = Random.Range(min, max);
                GameObject spawned = Instantiate(Dynamics[Random.Range(0, Dynamics.Count)], transform);
                spawned.transform.localPosition = new Vector3(0, spawned.transform.localPosition.y + Random.Range(-1f, 1f), 0);
                
                //spawned.transform.parent = parent;
            }
        }
    }
}
