- Home /
Changing Scene Crashes Unity while in play mode
I created 3 scenes and added them to build settings. To change the scene you have to hit the button. My first scene is the main menu, My second scene is the gameplay titled "FreeMode", And the 3rd scene is a copy of "FreeMode" titled "SpeedRun". I tried using the regular SceneManager.LoadScene(int) but it crashed immediately. So I changed my script to
using UnityEngine;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour {
public int Freemode;
public int SpeedRun;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnTriggerEnter(Collider other)
{
if(other.tag == "FreeMode")
{
StartCoroutine(Load1());
}
if (other.tag == "SpeedRun")
{
StartCoroutine(Load2());
}
if (other.tag == "Quit")
{
Application.Quit();
}
}
IEnumerator Load1()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(Freemode);
while (!operation.isDone)
{
Debug.Log(operation.progress);
yield return null;
}
}
IEnumerator Load2()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(SpeedRun);
while (!operation.isDone)
{
Debug.Log(operation.progress);
yield return null;
}
}
}
After I did this in the console, the progress reaches 0.9% before crashing. Is there any way to fix this?
Your answer
Follow this Question
Related Questions
Re-loading a scene but on the background older scenes are displayed 1 Answer
UnloadSceneAsync() does not seem to work with additive scenes. 1 Answer
Using scene created with SceneManager.CreateScene during runtime 0 Answers
Most efficient way to transition between scenes? 1 Answer
Using parameters of activeSceneChanged? 0 Answers