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


public class Spawner : MonoBehaviour {

    public GameObject enemy;
    public bool spawning = false;
    public float spawn_speed = 2.9f;

    // Use this for initialization
    void Start ()
    {
        
    }

    // Update is called once per frame
    void Update ()
    {        
        if (WaveController.enemy_wave == true & spawning == false)
        {          
            spawning = true;
            //Debug.Log("spawn");
            Instantiate(enemy, new Vector2(transform.position.x, transform.position.y), Quaternion.identity);
            StartCoroutine(Spawn());
        }
        if (WaveController.enemy_wave == false)
        {
            spawning = false;
        }

    }

    IEnumerator Spawn()
    {
        while (spawning == true)
        {        
            yield return new WaitForSeconds(spawn_speed);
            Instantiate(enemy, new Vector2(transform.position.x, transform.position.y), Quaternion.identity);
        }
    }
}
