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

public class Barracks : MonoBehaviour
{
    [Header("Stats")]
    public GameObject prefab;
    public Building buildingScript;
    public float intervalRandomizer;
    public float spawnInterval;
    public float maxAmount;

    [Header("Values")]
    public float spawnTimer;
    public List<GameObject> aliveAllies;

    //[Header("References")]
    //public List<ParticleSystem> emitters;

    private void Start()
    {
        spawnTimer = Random.Range(spawnInterval - intervalRandomizer, spawnInterval + intervalRandomizer);
    }

    private void Update()
    {
         spawnTimer -= Time.deltaTime;

        if (spawnTimer <= 0 & aliveAllies.Count < maxAmount)
        {
            spawnTimer = Random.Range(spawnInterval - intervalRandomizer, spawnInterval + intervalRandomizer);
            float xpos = transform.position.x + Random.Range(0, 3);
            float ypos = transform.position.y + Random.Range(0, 3);
            Vector2 pos = new Vector2(xpos, ypos);
            Instantiate(prefab, pos, transform.rotation, gameObject.transform);
        }
    }
}