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

public class BuildLevelScript : MonoBehaviour
{

    public GameObject[] invaderClasses;
    public int numColumns = 6;
    public int numRows = 4;

    // Start is called before the first frame update
    void OnEnable()
    {
        setupLevel();
    }

    public void setupLevel()
    {
        clearLevel();
        int numVaderTypes = invaderClasses.Length;
        for (int i = 0; i < numRows; i++)
        {
            for (int j = 0; j < numColumns; j++)
            {
                Instantiate(invaderClasses[i % numVaderTypes], transform.position - (transform.right * (numColumns / 2 - (j * 1.5f))) + (transform.up * (numRows + (i * 1.25f) - 4f)), transform.rotation);
            }
        }
    }

    void clearLevel()
    {
        GameObject[] invaders = GameObject.FindGameObjectsWithTag("Enemy");

        foreach(GameObject thisVader in invaders)
        {
            Destroy(thisVader);
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
