Skip to content

Instantly share code, notes, and snippets.

@inoto
Created March 21, 2018 08:50
Show Gist options
  • Save inoto/0f3febea163ee9c36217d82a4b7cb711 to your computer and use it in GitHub Desktop.
Save inoto/0f3febea163ee9c36217d82a4b7cb711 to your computer and use it in GitHub Desktop.
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);
}
}
}
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