Level selector was already working after work by William but some small bugs remained to be fixed + it wasn't possible to return to level selector once we were in the level. - it's now possible to go back to level selector from Level - LevelManagerScript is no longer a singleton (this way, it resets with the Game scene unloading) - Added a property drawer for using scene files in inspectors
38 lines
907 B
C#
38 lines
907 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class ChangeScene : MonoBehaviour
|
|
{
|
|
[Scene]
|
|
public string scene;
|
|
public SceneActionType sceneAction;
|
|
public LoadSceneMode loadSceneMode;
|
|
public enum SceneActionType
|
|
{
|
|
Load,
|
|
Unload
|
|
}
|
|
public void LoadScene()
|
|
{
|
|
if (sceneAction == SceneActionType.Load)
|
|
{
|
|
SceneManager.LoadScene(scene, loadSceneMode);
|
|
}
|
|
else if (sceneAction == SceneActionType.Unload)
|
|
{
|
|
for (int i = 0; i < SceneManager.sceneCount; i++)
|
|
{
|
|
var scene = SceneManager.GetSceneAt(i);
|
|
if (scene.name == this.scene)
|
|
{
|
|
SceneManager.UnloadSceneAsync(scene);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|