SpawnInCircle.cs 783 B

12345678910111213141516171819202122232425262728
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SpawnInCircle : MonoBehaviour
  5. {
  6. public GameObject Prefab;
  7. public float Radius = 1000;
  8. public float Amount = 10000;
  9. public bool DoIt;
  10. void Update()
  11. {
  12. if (DoIt && Prefab != null)
  13. {
  14. var rootPos = transform.position;
  15. var rot = transform.rotation;
  16. for (int i = 0; i < Amount; ++i)
  17. {
  18. var a = Random.Range(0, 360);
  19. var pos = new Vector3(Mathf.Cos(a), 0, Mathf.Sin(a));
  20. pos = rootPos + pos * Mathf.Sqrt(Random.Range(0.0f, 1.0f)) * Radius;
  21. Instantiate(Prefab, pos, rot, transform.parent);
  22. }
  23. }
  24. DoIt = false;
  25. }
  26. }