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

public class BlowingUp : MonoBehaviour {

    public GameObject[] pieces;
    public float size;
    public int amt;

    private void OnDestroy()
    {
        if (amt == 0) amt = 10;
        for (int i = 0; i < amt; i++)
        {
            int r = Random.Range(0, pieces.Length);
            Vector2 rat = Random.insideUnitCircle * size;
            GameObject g = GameObject.Instantiate(pieces[r], transform.position + (Vector3)rat, Quaternion.Euler(new Vector3(0,0,Random.Range(0,360))));
            g.GetComponent<Rigidbody2D>().velocity = Random.insideUnitCircle * 30;
            Destroy(g, 0.5f + Random.Range(0,1f));
        }
    }
}
