Unity does not change the scenes

1

In my Unity project I have these two scenes:

And I had this code to change the scene with a trigger:

void OnTriggerEnter2D(Collider2D other)
{

    //DETECTA TRIGGER PARA ENTRAR A CASA
    if(other.gameObject.name.Equals("casa")){
        Application.LoadLevel("casa");
    }

    //DETECTA TRIGGER SALIR DE CASA
    if(other.gameObject.name.Equals("salirDeCasa")){
        Application.LoadLevel("escenalibre");
    }
}

With this code worked perfectly, but the next day I opened the project and did not change the scenes and looking for Google I found this another way to do it:

void OnTriggerEnter2D(Collider2D other)
{

    //DETECTA TRIGGER PARA ENTRAR A CASA
    if(other.gameObject.name.Equals("casa")){
        SceneManager.LoadScene("casa",LoadSceneMode.Single);
    }

    //DETECTA TRIGGER SALIR DE CASA
    if(other.gameObject.name.Equals("salirDeCasa")){
        SceneManager.LoadScene("escenalibre",LoadSceneMode.Single);
    }
}

And adding the using UnityEngine.SceneManagement; .

Well, it does not work either ... But if I decide to change by the scene in which I am at that moment, if it changes by itself, it is as if being in a scene does not detect the others ...

Does anyone know if this has a solution? Or if I made a mistake in the code?

    
asked by Isaac 31.10.2018 в 11:04
source

1 answer

1

Notice that the scenes are selected and enabled in the Build Settings, even the editor asks to have the scenes indexed to be able to switch between them.

    
answered by 31.10.2018 в 19:14