using UnityEngine;
using System.Collections;

public class SpawnPoint : MonoBehaviour {

	[SerializeField] GameObject[] spawnObjects;
	[SerializeField] Transform spawnPoint;
	bool activated = false;


	float time = 0;
	float minTime = 1.0f;
	void Update()
	{
		time += Time.deltaTime;
	}

	void OnTriggerEnter(Collider collider)
	{
		if (collider.gameObject.tag == Tags.PLAYER)
		{
			if (time >= minTime || !activated )
			{
				for(int i = 0; i < spawnObjects.Length; i++)
				{
					Vector3 actualSpawnPoint = spawnPoint.position;
					actualSpawnPoint.x += 5*i;
					Instantiate((GameObject)spawnObjects[i], actualSpawnPoint, ((GameObject)spawnObjects[i]).transform.rotation);
				}
				time = 0;
				activated = true;
			}
		}
	}
}
