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

public class EnemySpawner : MonoBehaviour 
{
    [SerializeField]
    private GameObject EnemyPrefab;
    [SerializeField]
    private float cooldownForSpawning = 2.0f;
    private float timer;
    private DayTimeManager dayTimeManager;

	// Use this for initialization
	void Start () 
    {
        dayTimeManager = FindObjectOfType<DayTimeManager>();
	}
	
	// Update is called once per frame
	void Update () 
    {
        if (dayTimeManager.dayTimeLabel == DayTimeLabel.Night)
        {
            timer += Time.deltaTime;
            if (timer > cooldownForSpawning)
            {
                SpawnEnemy();
                timer = 0.0f;
            }
        }
	}

    private void SpawnEnemy()
    {
        GameObject enemy  = GameObject.Instantiate(EnemyPrefab);
        enemy.transform.position = this.transform.position;
    }
}
