What’s the problem? I can imagine you can’t unload a scene when there’s only one open scene. Maybe try putting Unload below Load.
By the way - those Async functions return AsyncOperation. You might need to LoadAsync and use AsyncOperation.isDone to determine when you can Unload the other scene.
So i understand my problem, “y” return the actif scene but the problem is i load everything in additive mode so “y” return my active “Player_load” scene the one where i load in additive my other scene …
So now i try to SetActive the last scene loaded but that’s not really work :
public Transform destination;
private bool lastUsePressedState = false;
public string sceneToLoadStr;
Scene scene;
private void OnTriggerStay(Collider collider)
{
var controller = (collider.GetComponent<VRTK_ControllerEvents>() ? collider.GetComponent<VRTK_ControllerEvents>() : collider.GetComponentInParent<VRTK_ControllerEvents>());
if (controller)
{
if (lastUsePressedState == true && !controller.usePressed)
{
StartCoroutine(Loading_Sea());
var distance = Vector3.Distance(transform.position, destination.position);
var controllerIndex = VRTK_DeviceFinder.GetControllerIndex(controller.gameObject);
OnDestinationMarkerSet(SetDestinationMarkerEvent(distance, destination, new RaycastHit(), destination.position, controllerIndex));
}
lastUsePressedState = controller.usePressed;
}
}
IEnumerator Loading_Sea()
{
AsyncOperation loadNewScene = SceneManager.LoadSceneAsync(sceneToLoadStr, LoadSceneMode.Additive);
loadNewScene.allowSceneActivation = false;
scene = SceneManager.GetSceneByName(sceneToLoadStr);
while (!loadNewScene.isDone)
{
float progress = Mathf.Clamp01(loadNewScene.progress / 0.9f);
Debug.Log (loadNewScene.progress);
if (loadNewScene.progress == 0.9f)
{
loadNewScene.allowSceneActivation = true;
Debug.Log("now set scene, " + scene.name + " active");
yield return new WaitForEndOfFrame();
SceneManager.SetActiveScene(SceneManager.GetSceneByName(scene.name));
SceneManager.UnloadSceneAsync("Salle_Choix");
yield return new WaitForSeconds(1);
Debug.Log("active scene is, " + SceneManager.GetActiveScene().name);
//Do your other stuff too.
}
yield return null;
}
}
But he always return “Player_Load” … And not the scene i load
I found working solution. Maybe it will be still relevant.
// Get count of loaded Scenes and last index
var lastSceneIndex = SceneManager.sceneCount - 1
// Get last Scene by index in all loaded Scenes
var lastLoadedScene = SceneManager.GetSceneAt(lastSceneIndex)
// Unload Scene
SceneManager.UnloadSceneAsync(lastLoadedScene);