using UnityEngine;
public class SpawnIll : MonoBehaviour
{
public int numberIll;
public GameObject illPrefab;
public Vector2 pos;
void Start()
{
for (int i = 1; i <= numberIll; i++)
{
pos=new Vector2(Random.Range(-1000,1001),Random.Range(-1000,1001));
Instantiate(illPrefab, pos, Quaternion.identity);
}
}
}
无论我选择什么是数字,团结都会崩溃。我认为它是无限循环的,但我不知道我做错了什么。
solved:创建的每个对象都会继续执行for循环,因此它只是创建了很多gameObjects。我使用了Coroutine,它起作用了。