In my game I have 2 scenes (MainMenu and Game) and in each level I have a game object that holds this code.
//MainMenu
public GameObject mainObjects;
public GameObject mainMenu;
public GUIText loading;
void Awake()
{
Screen.orientation = ScreenOrientation.Portrait;
}
void Start()
{
StartCoroutine(WaitFewSeconds(2));
}
IEnumerator WaitFewSeconds(float waitTime)
{
loading.text = "Loading...";
yield return new WaitForSeconds(waitTime);
gameObject.SetActive(false);
mainObjects.SetActive(true);
mainMenu.SetActive(true);
}
//Game
//Object to enable
public GameObject mainObjects;
public GameObject terrain;
public GUIText loading;
void Awake()
{
Screen.orientation = ScreenOrientation.LandscapeLeft;
}
void Start()
{
StartCoroutine(WaitFewSeconds(2));
}
IEnumerator WaitFewSeconds(float waitTime)
{
loading.text = "Loading...";
yield return new WaitForSeconds(waitTime);
gameObject.SetActive(false);
mainObjects.SetActive(true);
terrain.SetActive(true);
}
The problem is that sometimes(pretty often) the game freezes at loading and the yield is not called.
The thing is that its not when I do something or at a specific time. Sometimes it works sometimes it doesn’t.
I did tried to only using the yield and nothing else but I still had the problem.