Created
March 21, 2018 08:50
-
-
Save inoto/0f3febea163ee9c36217d82a4b7cb711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour | |
{ | |
public static T Instance { get; private set; } | |
protected void Awake() | |
{ | |
if (Instance == null) | |
{ | |
Instance = this as T; | |
DontDestroyOnLoad(gameObject); | |
} | |
else | |
{ | |
Destroy(gameObject); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoadingManager : Singleton<LoadingManager> | |
{ | |
public void LoadNextScene() | |
{ | |
int activeSceneIndex = SceneManager.GetActiveScene().buildIndex; | |
SceneManager.LoadScene(activeSceneIndex + 1); | |
} | |
public void LoadPreviousScene() | |
{ | |
int activeSceneIndex = SceneManager.GetActiveScene().buildIndex; | |
SceneManager.LoadScene(activeSceneIndex - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment