Почему мой цикл for повторяется бесконечно?
Я имею код, который должен повторяться столько раз, сколько написано в движке, но когда я ставлю например любое число, мой цикл повторяется бесконечно, почему это?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Stars : MonoBehaviour
{
public Camera Camera;
public GameObject Object;
public float StarCount;
void Start()
{
StartCoroutine(CreateStars());
}
IEnumerator CreateStars()
{
Vector3 camTopLeftWorld = Camera.ViewportToWorldPoint (new Vector3 (0,1,Camera.nearClipPlane));
Vector3 camTopRightWorld = Camera.ViewportToWorldPoint (new Vector3 (1,1,Camera.nearClipPlane));
Vector3 camBottomLeftWorld = Camera.ViewportToWorldPoint (new Vector3 (0,0,Camera.nearClipPlane));
for(int i = 0; i <= StarCount; i++)
{
GameObject Star = Instantiate(Object);
Star.transform.position = new Vector3(Random.Range(camTopLeftWorld.x, camTopRightWorld.x), Random.Range(camTopLeftWorld.y, camBottomLeftWorld.y));
yield return new WaitForSeconds(1);
}
}
}
Так выглядит цикл. Переменную StarCount
я задаю в самом Unity.