using UnityEngine;
using System.Collections;

public class DebrisSpawner : MonoBehaviour {

	// Use this for initialization
    int frames = 0;
    GameObject startPos; 
    void Start () {
        startPos = GameObject.Find("DebrisStart");
	}
	
	// Update is called once per frame
	void Update () {
        if (frames == 2)
        {
            float randangle = Random.value * 2.0f * Mathf.PI;
            float rad = Random.value * 128.0f;
            rad = Mathf.Clamp(rad, 64.0f, 128.0f);
            float nz = Mathf.Cos(randangle) * rad;
            float ny = Mathf.Sin(randangle) * rad;

            Vector3 newpos = startPos.transform.position + (new Vector3(0.0f, ny, nz));
            GameObject newDeb = GameObject.Instantiate(Resources.Load("Debris"), newpos, Quaternion.identity) as GameObject;
            frames = 0;
        }
        frames++;
	}
}
