Unity not playing game in editor
Hi, I recently game across a problem. Whenever I press the play button, unity sits there and takes forever to load the game. I have waited about 20 minutes and nothing has happened. Everything was working fine until I added these two scripts:
MenuScript.js:
var isOnList: boolean;
MenuManager.js:
#pragma strict
var MenuList : GameObject[];
var MenuID : int;
var TotalMenus : int;
var MenuActive : boolean;
var ActiveMenus : int;
function Start () {
TotalMenus = UnityScript.Lang.Extensions.get_length(MenuList);
}
function Update () {
while (MenuID < TotalMenus)
{
if (MenuList[MenuID].activeInHierarchy)
{
ActiveMenus = ActiveMenus + 1;
if (!MenuList[MenuID].GetComponent(MenuScript).isOnList)
{
MenuList[MenuID].GetComponent(MenuScript).isOnList = true;
}
MenuID = MenuID + 1;
}
else
{
if (!MenuList[MenuID].activeInHierarchy)
{
if (MenuList[MenuID].GetComponent(MenuScript).isOnList)
{
ActiveMenus = ActiveMenus - 1;
MenuList[MenuID].GetComponent(MenuScript).isOnList = false;
MenuID = MenuID + 1;
}
}
else
{
MenuID = MenuID + 1;
}
}
}
if (ActiveMenus != 0 && !MenuActive)
{
MenuActive = true;
}
if (ActiveMenus == 0 && MenuActive)
{
MenuActive = false;
}
if (PlayerPrefs.GetInt("MenuActive") != 1 && MenuActive)
{
PlayerPrefs.SetInt("MenuActive", 1);
}
if (PlayerPrefs.GetInt("MenuActive") != 0 && !MenuActive)
{
PlayerPrefs.SetInt("MenuActive", 0);
}
}
This is very annoying and I want to get a new build of my game out by March 15th, 2016. Thank you in advance.
Answer by CreeperSeth · Mar 11, 2016 at 03:31 AM
Went back to my ghetto ways and removed the fix so its fine
Answer by silentninjastudio · Jun 02, 2016 at 08:04 PM
@CreeperSeth How did you fix the problem? I am now facing the same issue.
Answer by $$anonymous$$ · Jul 06, 2019 at 08:48 PM
Your while loop is infinite. The condition never changes, so the loop never exits and the game cannot move on.
Your answer
Follow this Question
Related Questions
Unity stops responding after Play 0 Answers
Unity totally freezes 1 Answer
Stop unity project from playing when not responding 0 Answers
Zombunny not properly responding 1 Answer
Unity Editor doesn't load properly 1 Answer