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

[Serializable]
public struct WaveEntry
{
	public Vector2 position;
	public Transform prefab;
}

public class WaveTrigger : MonoBehaviour {
	public List<WaveEntry> Wave;
	public float StartupDelay=0f;

	void OnTriggerEnter2D(Collider2D col)
	{
		if(col.gameObject.tag == "Player")
		{
			SpawnWave();
		}
	}

	private void SpawnWave()
	{
		int count = 0;
		foreach(WaveEntry e in Wave)
		{
			Transform t = (Transform)GameObject.Instantiate(e.prefab);
			t.position = transform.position + (Vector3)e.position;

			FlyingMovementController f = t.GetComponent<FlyingMovementController>();
			if(f != null)
				f.StartupDelay = (float)count * StartupDelay;

			count++;
		}

		GameObject.Destroy(gameObject);
	}
}
