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

public class SpawnerScript : MonoBehaviour {

    public Player player;
    public int wave = 1;
    public GameObject[] spawnSites;
    public GameObject[] enemies;

    // Use this for initialization
    void Start () {
        spawnSites = GameObject.FindGameObjectsWithTag("Spawner");
        foreach (GameObject go in spawnSites)
        {
            GameObject enemy = Instantiate(Resources.Load("R_1", typeof(GameObject))) as GameObject;
            EnemyAIVer2 ai = enemy.gameObject.GetComponent<EnemyAIVer2>();
            ai.gameObject.transform.position = go.transform.position;
            ai.player = player.gameObject;
            ai.playerPos = player.gameObject.transform;
        }
    }
	
	// Update is called once per frame
	void Update () {
        enemies = GameObject.FindGameObjectsWithTag("Enemy");
        if (enemies.Length <= 1 || Input.GetKeyDown(KeyCode.Q))
        {
            wave++;
            for (int i = 0; i < wave; i++)
            {
                foreach (GameObject go in spawnSites)
                {
                    GameObject enemy = Instantiate(Resources.Load("R_1", typeof(GameObject))) as GameObject;
                    EnemyAIVer2 ai = enemy.gameObject.GetComponent<EnemyAIVer2>();
                    ai.player = player.gameObject;
                    ai.playerPos = player.gameObject.transform;
                }
            }
        }
	}
}
