I am making a platformer where at the end of the level you collect a coin that loads the next level. The code works but right now it loads the same scene every time. I would like it to load the name (string) of the scene that I tell it to in the inspector.
Any help is greatly appreciated!
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class PlayButton : MonoBehaviour
{
public void NextLevelButton(int index)
{
SceneManager.LoadScene(1); ;
}
}
so try going to build settings and then add all your scenes to the build, now you should be able to change scene depending on the number but that would mean you would have to make a new script for every time you want to change the scene so here is a little script I made for you:
public int currentScene;
void Update()
{
currentScene = SceneManager.GetActiveScene().buildIndex;
}
public void NextLevelButton(int index)
{
SceneManager.LoadScene(currentScene + 1);
}
This should get the scene and then bring it to the next level
Did you try using Application.LoadLevel ?
Application.LoadLevel(string name);