- Home /
Question by
stefanpopescu99 · Feb 24, 2019 at 10:23 AM ·
crashvisual studio
Unity crashes when using Instantiate inside for loop. Solved: every object created keeps doing the for loop so it just creates lots of gameobjects. I used coroutine and it worked.
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);
}
}
}
No matter what I choose as numberIll, the Unity will crash. I think it goes in an infinite loop but I don't know what I did wrong.
Comment
Your answer
Follow this Question
Related Questions
Unity 4 hangs when opening Visual Studio 2008? 0 Answers
Debugging crash.dmp 0 Answers
Visual Studio 2015 debugging unstable. VS attached 1 Answer
Debugging 'Assertion failed on expression' errors. 0 Answers