Yoh guys! I use this script to go from one scene to another:
public int index;
public string Level;
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag ("Player"))
{
SceneManager.LoadScene(2);
}
}
the issue is that i have multilpe scene (like 8 different level) and, for example, to go from the first scene to the second and from the second to the third using this script it is not possible. Someone can help me with a script or an explanation? Thanks in advance.
According to the documentation, LoadScene(int sceneBuildIndex) works by looking for the provided index in the Build Settings. Make sure all of your scenes are properly indexed in the Build Settings.
If you’d rather, you could also use LoadScene(string sceneName) to load your scenes, by simply providing with their name (which is the same as their filename, without the .unity extension). If you have multiple scenes with the same name but in different folders, use their full path instead (still without the .unity extension).
For more information, visit:
@AncillaryJustice
You would need to index all scenes in sequence in build settings. Then you can use
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1);
This will take you to the subsequent scene.