You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class DebrisController : MonoBehaviour {
  4. public int count;
  5. public GameObject debris;
  6. public Transform minPos;
  7. public Transform maxPos;
  8. // Use this for initialization
  9. void Start () {
  10. for (int i = 0; i < count; i++) {
  11. Vector2 randPos = Vector2.zero;
  12. randPos.x = Random.Range(Mathf.Min(minPos.position.x, maxPos.position.x), Mathf.Max(minPos.position.x, maxPos.position.x));
  13. randPos.y = Random.Range(Mathf.Min(minPos.position.y, maxPos.position.y), Mathf.Max(minPos.position.y, maxPos.position.y));
  14. Vector3 randRot = Vector3.zero;
  15. randRot.z = Random.Range(0, 360);
  16. GameObject temp = (GameObject) Instantiate(debris, randPos, Quaternion.Euler(randRot));
  17. temp.transform.localScale = Vector3.one * 3;
  18. temp.transform.parent = transform;
  19. Rigidbody2D rigid = temp.GetComponent<Rigidbody2D>();
  20. rigid.AddTorque(Random.Range(3f, 5f));
  21. }
  22. }
  23. // Update is called once per frame
  24. void Update () {
  25. }
  26. }