- Home /
Not loading scene on build
Hi, I've got a script that shows a splash screen for a certain amount of time, then takes me to a new scene. Only problem is, it works very good inside the editor. Although when I build the game, and run it by the .exe file, it does nothing.
using UnityEngine;
using System.Collections;
public class splashscreen1 : MonoBehaviour {
[Header ("Object Type")]
public int timer;
public Object nextScene;
// Use this for initialization
void Start () {
StartCoroutine (loadSceneAfterDelay(timer));
}
IEnumerator loadSceneAfterDelay(float waitbySecs){
yield return new WaitForSeconds(waitbySecs);
Application.LoadLevel(nextScene.name);
}
}
What am I doing wrong?
Are you making sure to include the scene you want to load when building?
Yes the scene is included when building. If its not it usually throws an error at me inside the editor. If I remove the splash screens, and put the scene that I'm trying to get them to go to, it works. But I want the splash screens there.
And there are no errors/warnings when debugging the build? Have you tried logging if the coroutine gets called and if it finishes?
When debugging, theres no error or warnings at all. Works perfectly fine. Just when running the .exe, it fails to work
Answer by Paricus · Dec 06, 2016 at 10:16 AM
Unity has switched to SceneManager to handle its scenes. you should find what you need here: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
Application.LoadLevel() is deprecated
I did Scene$$anonymous$$anager.LoadScene (nextScene.name); Still same result. Will work in editor. Won't work in build
Try a development build, the log should show you any errors
Thank you for your reply. I received this error. Which ponits to the line: Scene$$anonymous$$anager.LoadScene (nextScene.name);
Try Scene$$anonymous$$anager.LoadScene (0);
If that works. It's an issue with nextScenes. name
This does indeed work. Would you have any idea what would be wrong with nextScenes.name? Or is there any better way that I could go about doing this?
I'm not familiar with next scene.name
Is it your own code.