JeCodeLeSoir

Untitled

Mar 3rd, 2024
695
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TestWhile : MonoBehaviour
  6. {
  7.     [SerializeField] GameObject prefabs;
  8.     [SerializeField] int Max = 400;
  9.    
  10.     List<Vector3> positions = new List<Vector3>();
  11.    
  12.     void Start()
  13.     {
  14.         StartCoroutine(test());
  15.     }
  16.    
  17.     IEnumerator Spawn(Vector3 p)
  18.     {
  19.         Instantiate(prefabs, p, Quaternion.identity);
  20.  
  21.         yield return null;
  22.     }
  23.    
  24.     IEnumerator test()
  25.     {
  26.         do
  27.         {
  28.             if (positions.Count >= Max)
  29.                 break;
  30.            
  31.             var position_random = new Vector3(
  32.                 Random.Range(-10, 10), 0, Random.Range(-10, 10));
  33.  
  34.             if (!positions.Contains(position_random)) {
  35.                 positions.Add(position_random);
  36.                 yield return Spawn(position_random);
  37.             }
  38.             else
  39.                 yield return null;
  40.  
  41.         }
  42.         while (true);
  43.     }
  44.  
  45. }
  46.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment