Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TestWhile : MonoBehaviour
- {
- [SerializeField] GameObject prefabs;
- [SerializeField] int Max = 400;
- List<Vector3> positions = new List<Vector3>();
- void Start()
- {
- StartCoroutine(test());
- }
- IEnumerator Spawn(Vector3 p)
- {
- Instantiate(prefabs, p, Quaternion.identity);
- yield return null;
- }
- IEnumerator test()
- {
- do
- {
- if (positions.Count >= Max)
- break;
- var position_random = new Vector3(
- Random.Range(-10, 10), 0, Random.Range(-10, 10));
- if (!positions.Contains(position_random)) {
- positions.Add(position_random);
- yield return Spawn(position_random);
- }
- else
- yield return null;
- }
- while (true);
- }
- }
Advertisement