using UnityEngine; using System.Collections; public class DebrisController : MonoBehaviour { public int count; public GameObject debris; public Transform minPos; public Transform maxPos; // Use this for initialization void Start () { for (int i = 0; i < count; i++) { Vector2 randPos = Vector2.zero; randPos.x = Random.Range(Mathf.Min(minPos.position.x, maxPos.position.x), Mathf.Max(minPos.position.x, maxPos.position.x)); randPos.y = Random.Range(Mathf.Min(minPos.position.y, maxPos.position.y), Mathf.Max(minPos.position.y, maxPos.position.y)); Vector3 randRot = Vector3.zero; randRot.z = Random.Range(0, 360); GameObject temp = (GameObject) Instantiate(debris, randPos, Quaternion.Euler(randRot)); temp.transform.localScale = Vector3.one * 3; temp.transform.parent = transform; Rigidbody2D rigid = temp.GetComponent(); rigid.AddTorque(Random.Range(3f, 5f)); } } // Update is called once per frame void Update () { } }