- Home /
HELP! my game is freezing while trying to instantiate objects...
Hi, thanks for the help... Okay, I am making a maze-like game, and I have come across an issue. The game is randomly generated. I do it here in my code on the start of the scene.
void Start () {
loadingt.enabled = false;
loadingi.enabled = false;
loadingpr = false;
destroy2 = false;
data.dfloor = 1;
data.loading = true;
data.totalkey = 0;
data.totalchest = 0;
RenderSettings.ambientLight = colors[(Random.Range(0,4))];
tempchest = 0;
realxsize = 2;
realysize = 2;
data.xsize = realxsize;
data.ysize = realysize;
optimize();
data.loading = false;
}
If you need a more specific look at a function then ask. For the optimize function, it is
public void optimize()
{
CreateWalls();
namewall();
special();
}
and I actually refrence 2 more funtions as well, but like I said, ask if you need them. Okay, when I start the scene for the first time it loads great. hoooowever, it freezes and crashes my engine when trying to reload the scene mid game, let me explain, When you get to the end, you trigger a regeneration of the maze. here,
void Update()
{
if (data.loading == true)
{
StartCoroutine(wait());
loadingt.enabled = true;
loadingi.enabled = true;
loadingpr = true;
data.dfloor++;
realysize++;
realxsize++;
data.xsize = realxsize;
data.ysize = realysize;
StartCoroutine(wait());
destroy();
StartCoroutine(wait());
CreateWalls();
StartCoroutine(wait());
}
Now the issue is when I go to regenerate the game it just freezes. I have narrowed it down to just the CreateWalls() function, yet, even with the Waits, it still just crashes... HELP!
this line doesn't wait the execution inside Update loop, StartCoroutine(wait());
if you need that to happen, put all that code inside coroutine, and then call this to wait for that line: yield return StartCoroutine(wait());
Your answer
Follow this Question
Related Questions
Unity freezes after adding a new script 1 Answer
The Pause of Death - Unity's system freeze causes many issues. 0 Answers
New User Questions 1 Answer
Where do I start with unity? 3 Answers