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?