JeCodeLeSoir

Untitled

Mar 3rd, 2024
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TestWhile : MonoBehaviour
  6. {
  7.     List<Vector3> positions = new List<Vector3>();
  8.    
  9.     void Start()
  10.     {
  11.         StartCoroutine(test());
  12.     }
  13.    
  14.     IEnumerator Spawn(Vector3 p)
  15.     {
  16.         GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
  17.        
  18.         obj.transform.position = p;
  19.        
  20.         index += 0.5f;
  21.  
  22.         yield return null;
  23.     }
  24.  
  25.  
  26.     float index = 0;
  27.     IEnumerator test()
  28.     {
  29.         do
  30.         {
  31.  
  32.             var listDir  = new List<Vector3> {
  33.                 Vector3.up,
  34.                 Vector3.down,
  35.                 Vector3.left,
  36.                 Vector3.right,
  37.                 Vector3.forward,
  38.                 Vector3.back,
  39.  
  40.                 Vector3.up+Vector3.left,
  41.                 Vector3.up+Vector3.right,
  42.  
  43.                 Vector3.down+Vector3.left,
  44.                 Vector3.down+Vector3.right,
  45.  
  46.                 Vector3.up+Vector3.forward,
  47.                 Vector3.up+Vector3.back,
  48.  
  49.                 Vector3.down+Vector3.forward,
  50.                 Vector3.down+Vector3.back,
  51.  
  52.                 Vector3.left+Vector3.forward,
  53.                 Vector3.left+Vector3.back,
  54.  
  55.                 Vector3.right+Vector3.forward,
  56.                 Vector3.right+Vector3.back,
  57.             };
  58.  
  59.             var randomDirection = listDir[Random.Range(0, listDir.Count)] * index;
  60.  
  61.             if (!positions.Contains(randomDirection)) {
  62.                 positions.Add(randomDirection);
  63.                
  64.                 yield return Spawn(randomDirection);
  65.             }
  66.             else
  67.                 yield return null;
  68.         }
  69.         while (true);
  70.     }
  71.  
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment