- Home /
Placing scene object in inspector as a varable and load with button in game
Hello I am a noob, I am trying to load a scene by setting the scene as a variable, with the idea of simply changing the object from the inspector. Here's what i'm doing.
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadScene : MonoBehaviour
public Object nextScene;
public void LoadSceneSelect()
{
SceneManager.LoadScene(nextScene.name);
}
(SelectLevel is another scene that I am using to load different levels of the game) not sure what i am doing wrong, or if this is even possible and i schould just load it by using the name or index. thank you.
Answer by Fake_Ludo · Feb 02 at 03:06 PM
I managed to fix it here's what my friend @voidUpdat suggested
public string nextScene;
public void LoadSceneSelect()
{
SceneManager.LoadScene(nextScene);
}
instead of using the script i am using the button on the OnClick. and then writing the name of the scene in the intring variable which makes loading different sences more easily.