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

public class SpawnTanks : MonoBehaviour {

    public GameObject[] tanks;
    public Transform spawnPoint;
    public int spawnCount;

    public float startTime, waveTime, spawnTime;


    void Start () {
        StartCoroutine(SpawnEnemyTank());
	}
	
	void Update () {
		
	}

    IEnumerator SpawnEnemyTank()
    {
        yield return new WaitForSeconds(startTime);
        while (true)
        {
            for (int i = 0; i < spawnCount; i++)
            {
                transform.position = new Vector3(spawnPoint.position.x, spawnPoint.position.y, spawnPoint.position.y);
                Quaternion spawnRotation = Quaternion.identity;
                int randomNumber = Random.Range(0, 2);

                Instantiate(tanks[randomNumber], transform.position, spawnRotation);

                yield return new WaitForSeconds(spawnTime);
            }

            yield return new WaitForSeconds(waveTime);
        }
    }
}
