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

public class EnemyControl : MonoBehaviour
{
    public List<GameObject> enemies = new List<GameObject>();
    public GameObject[] enemyPrefabs;
    public Transform player;
    float timer;
    float score;
    public Text scorecounter;
    // Use this for initialization
    void Start()
    {
        for (float i = 20; i < 90; i += (Random.Range(50, 101) * 0.1f))
        {
            int r = Random.Range(0, enemyPrefabs.Length);
            NewEnemy(enemyPrefabs[r], new Vector3(-45 + i, 1, 0), r);
        }
    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        score += Time.deltaTime;
        scorecounter.text = ((int)score).ToString();
        if (timer >= 5.0f/(score * 0.01f))
        {
            timer = 0;
            int r = Random.Range(0, enemyPrefabs.Length);
            NewEnemy(enemyPrefabs[r], new Vector3(45, 1, 0), r);
        }
    }

    void NewEnemy(GameObject _Pre, Vector3 _Pos, int _I)
    {
        GameObject newEnemy = Instantiate(_Pre, _Pos, Quaternion.Euler(0, 0, 0));
        enemies.Add(newEnemy);
        //if (_I == 0)
        //{
        //    newEnemy.GetComponent<Frontline>().SetTarget(player);
        //    newEnemy.GetComponent<Frontline>().SetSpeed(5);
        //    //newEnemy.GetComponent<Frontline>().origin = gameObject;
        //}
        //if (_I == 1)
        //{
        //    newEnemy.GetComponent<Ranger>().SetTarget(player);
        //    newEnemy.GetComponent<Ranger>().SetSpeed(3);
        //    //newEnemy.GetComponent<Ranger>().origin = gameObject;
        //}
    }
}
