CopyObject.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System.Collections;
  5. using UnityEngine;
  6. namespace MagicaCloth
  7. {
  8. public class CopyObject : MonoBehaviour
  9. {
  10. public int seed = 0;
  11. public int count = 1;
  12. public float radius = 5;
  13. public GameObject prefab;
  14. //public bool delay = false;
  15. public int delayFrame = 0;
  16. private void Awake()
  17. {
  18. }
  19. void Start()
  20. {
  21. StartCoroutine(CreateObject());
  22. }
  23. IEnumerator CreateObject()
  24. {
  25. Random.InitState(seed);
  26. for (int i = 0; i < count; i++)
  27. {
  28. var obj = GameObject.Instantiate(prefab);
  29. var lpos = Random.insideUnitCircle * radius;
  30. obj.transform.position = transform.position + new Vector3(lpos.x, 0.0f, lpos.y);
  31. //if (delay)
  32. // yield return null;
  33. if (delayFrame > 0)
  34. for (int j = 0; j < delayFrame; j++)
  35. yield return null;
  36. }
  37. }
  38. }
  39. }