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
- {
- List<Vector3> positions = new List<Vector3>();
- void Start()
- {
- StartCoroutine(test());
- }
- IEnumerator Spawn(Vector3 p)
- {
- GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- obj.transform.position = p;
- index += 0.5f;
- yield return null;
- }
- float index = 0;
- IEnumerator test()
- {
- do
- {
- var listDir = new List<Vector3> {
- Vector3.up,
- Vector3.down,
- Vector3.left,
- Vector3.right,
- Vector3.forward,
- Vector3.back,
- Vector3.up+Vector3.left,
- Vector3.up+Vector3.right,
- Vector3.down+Vector3.left,
- Vector3.down+Vector3.right,
- Vector3.up+Vector3.forward,
- Vector3.up+Vector3.back,
- Vector3.down+Vector3.forward,
- Vector3.down+Vector3.back,
- Vector3.left+Vector3.forward,
- Vector3.left+Vector3.back,
- Vector3.right+Vector3.forward,
- Vector3.right+Vector3.back,
- };
- var randomDirection = listDir[Random.Range(0, listDir.Count)] * index;
- if (!positions.Contains(randomDirection)) {
- positions.Add(randomDirection);
- yield return Spawn(randomDirection);
- }
- else
- yield return null;
- }
- while (true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment