using UnityEngine;
using System.Collections;

public class EnemySpawner : MonoBehaviour 
{
	public GameObject[] enemies;
	public GameObject boss;
	public float spawnRate = 5;

	[Range(0,100)]
	public int chanceToSpawnType1;
	[Range(0,100)]
	public int chanceToSpawnType2;
	[Range(0,100)]
	public int chanceToSpawnType3;
	public int BossTime = 60;
	public bool hasSpawnedBoss = false;
	public float startDelay = 5;


	void Start () 
	{
		InvokeRepeating("SpawnEnemy",startDelay,spawnRate);
	//	transform.LookAt(GameObject.FindWithTag("Player").transform);
	}

	void SpawnEnemy()
	{
		if(Time.time >= BossTime && !hasSpawnedBoss)
		{
			hasSpawnedBoss = true;
			Instantiate(boss,transform.position,Quaternion.identity);
		}
		else if(Random.Range(0,100) < chanceToSpawnType1)
			Instantiate(enemies[0],transform.position,transform.rotation);
		else if(Random.Range(0,100) < chanceToSpawnType2)
			Instantiate(enemies[1],transform.position,transform.rotation);
		else if(Random.Range(0,100) < chanceToSpawnType3)
			Instantiate(enemies[2],transform.position,transform.rotation);
	}

}
