In my game I have 2 scenes (MainMenu and Game) and in each level I have a game object that holds this code. Code (CSharp): //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.
You might have more luck using actual Unity scenes (separate .unity files), say one called MainMenu and one called Playing. Each scene has its own script. The Start() method could set your portrait/landscape. Each scene would ONLY contain what you need for it: - main menu has main menu components - playing has game components and terrain. Then in code, when it's time to go from one to the other, you would use: Code (csharp): Application.LoadLevel( "MainMenu"); If you have a main menu and handful of levels, you would choose which one to load next. Be sure you add all the scenes you want to the BuildSettings window. Kurt
You mean to create 2 more scenes that are going to hold the portrait and landscape code with the yield in them ?
No need to yield, if what you want is to execute some logic after the level is loaded. http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html I don't know if that method is called after the Start() method of your objects though, just test it out.
I fixed the problem. I was setting Time.timeScale to 0 in game scene and in mainmenu was still 0 that's why nothing was working.