[Header("Levels To Load")]
public Scene _newGameLevel;
private string levelToLoad;
And in the inspector :
There is no field to drag or select a scene. The New Game Level is just a static text.
Before that i used string instead Scene and then i had to type the scene name in text to load. but now i want instead typing each time the scene to load just to drag a scene to the inspector and get the name of it.
This is how i use it :
StartCoroutine(sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, _newGameLevel.name));
but there is no Scene field to drag any scene to it. This screenshot show my scenes and the scene i want to drag to the script is the Starter.
CodePudding user response:
Scene Assets cannot be serialized in the Inspector.
But I can give you one idea to solve the problem you are facing.
* IDEA
Instead of directly assigning a Scene Asset to the Inspector, you only need to assign a string corresponding to the Scene.
* SOLVED
I solved it in the following way. However, this method requires a paid package called Odin Inspector.
public class Test : MonoBehaviour
{
[ValueDropdown("SelectScene", DropdownTitle = "Scene Selection")]
public string sceneName;
private static IEnumerable SelectScene()
{
var filesPath = Directory.GetFiles("Assets/Scenes");
var fileNameList = filesPath
.Select(Path.GetFileName)
.Select(file => file.Split(".")[0])
.Distinct()
.ToList();
return fileNameList;
}
}
You can use it like this :
StartCoroutine(
sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, sceneName));
There will be other ways besides this one. But, that's all I can do with my abilities.
Hope your problem is solved :)