using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour
{
public GameObject[ ] spawnright;
public GameObject[ ] spawnup;
public GameObject[ ] spawnleft;
int wave;
float pauze;
float spawnInterval;
int spawnsLeft;
void Start()
{
Reset();
}
void Update()
{
if (pauze <= 0)
{
if (spawnInterval <= 0 && spawnsLeft > 0)
{
int side = Random.Range(0, 3);
if (side == 0)
{
GameObject enemyright = (GameObject)Instantiate(spawnright[Random.Range(0, spawnright.Length)], new Vector3(transform.position.x, Random.Range(-.5f, 5), 0), Quaternion.identity);
}
if (side == 1)
{
GameObject enemyleft = (GameObject)Instantiate(spawnleft[Random.Range(0, spawnleft.Length)], new Vector3(Random.Range(0, 10), Random.Range(0, 10), 0), Quaternion.identity);
}
if (side >= 2)
{
GameObject enemyup = (GameObject)Instantiate(spawnup[Random.Range(0, spawnup.Length)], new Vector3(Random.Range(-10, 10), transform.position.y, 0), Quaternion.identity);
}
spawnsLeft -= 1;
spawnInterval = Random.Range(0, 200) / 100f;
}
else
{
spawnInterval -= Time.deltaTime;
}
}
else
{
pauze -= Time.deltaTime;
}
if (spawnsLeft <= 0)
{
Reset();
}
}
void Reset()
{
wave += 1;
pauze = 5f - wave * 0.5f;
spawnsLeft = 10 + wave * 2;
}
}