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

public class DropOnDestroy : MonoBehaviour {

	public List<Transform> Drops;	
	public float Spread=0.75f;

	private GameController gc;	

	void Start () {
		GameObject go = GameObject.Find ("GameController");
		gc = go.GetComponent<GameController>();
	}

	void OnDestroy() {
		Drop();
	}

	private void Drop()
	{
		if(!gc.CurrentLevel.Over)
		{
			foreach(Transform p in Drops)
			{
				Transform d = (Transform) GameObject.Instantiate(p);
				d.position = GetRandomPosition() + transform.position;
				gc.CurrentLevel.Transforms.Add (d);
			}
		}
	}

	private Vector3 GetRandomPosition()
	{
		return new Vector3((float)gc.rand.NextDouble()*2 - 1, (float)gc.rand.NextDouble()*2 - 1).normalized * Spread;
	}

}
