- Home /
How to write a change Scene 2d for multiple scene
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.
Answer by Ramlock · Mar 26, 2018 at 03:52 AM
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: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
Answer by Priyanka-Rajwanshi · Mar 26, 2018 at 05:11 AM
@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.
Happy to help :) Do accept the answer if it solved your problem.
Your answer
Follow this Question
Related Questions
Scenes overlap in Game view in Editor and Game is stuck in Main menu after installing in mobile. 1 Answer
Generate Tiles Programatically Over Player Position? 0 Answers
How to close up charactor ? And move charactor to charactor 2D ? 0 Answers
Endless level generation not instantiading 0 Answers
(2D) Can't make a scene transition between 2 game objects colliding - 2019 1 Answer