using UnityEngine;
using System.Collections;
using System;

public class PowerUpSpawner : MonoBehaviour {
	
	public GameObject prefabPowerUp;
	public float	spawnPowerEverySeconds = 10.0f;
	
	[HideInInspector]
	public bool isReady = false;
	
	GameObject[] floors;
	DateTime dateLastDrop;
	bool IsActive = false;

	public void Init () {
		floors = GameObject.FindGameObjectsWithTag("Floor");
		dateLastDrop = DateTime.Now;
		isReady = true;
	}
	
	void Update(){
		if (isReady && DateTime.Now >= dateLastDrop.AddSeconds(spawnPowerEverySeconds))
			Drop();
	}
	
	void Drop(){
		dateLastDrop = DateTime.Now;
		int rnd = UnityEngine.Random.Range (0, floors.Length - 1);
		Debug.Log("rd : " + rnd.ToString() + " size : " +  floors.Length.ToString());
		Vector3 temp = floors [rnd].transform.position;
		temp.z -= 1.00f;
		Instantiate(prefabPowerUp, temp, Quaternion.identity);
	}
}