Scene May Not Load with LoadLevelAsync

Asked 1 years ago, Updated 1 years ago, 37 views

public void load(string name){
    StartCoroutine (LoadNextLevel(name)));
}

IEnumerator LoadNextLevel(string name){
    AsyncOperation ao=Application.LoadLevelAsync(name);
    ao.allowSceneActivation=false;

    while(ao.progress<0.9f){
        yield return new WaitForEndOfFrame();
    }
    // Transition to next level
    ao.allowSceneActivation=true;

    yield return null;
}

The above script is started during scene transition.
If you repeat the scene transition from A to B to A to B, the scene transition after the second time may not be performed.Specifically, the ao.progress value is always 0.
Do you know the cause or solution?

unity 5.2.2

c# unity3d

2022-09-30 16:10

1 Answers

When the scene transitions overlap, the same phenomenon is true.
I think there will probably be no problem if the scene transition is performed exclusively.

I've done minimal modifications.

AsyncOperation ao;

public void load (string name) {
    if(ao!=null)return;
    StartCoroutine (LoadNextLevel(name)));
}

IEnumerator LoadNextLevel(string name){
    ao=Application.LoadLevelAsync(name);
    ao.allowSceneActivation=false;

    while(ao.progress<0.9f){
        yield return new WaitForEndOfFrame();
    }
    // Transition to next level
    ao.allowSceneActivation=true;
    ao = null;

    yield return null;
}


2022-09-30 16:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.