Files
Scampz/Assets/Scripts/GameManager.cs
2022-08-14 16:49:18 -07:00

54 lines
1.3 KiB
C#

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Scampz.GameJam
{
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public Animator animator;
void Awake()
{
if (Instance == null)
{
Instance = this;
}
}
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
{
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
}
public void UnloadScene(string sceneName)
{
StartCoroutine(UnloadSceneAsync(sceneName));
}
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
{
yield return null;
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
loadSceneOperation.allowSceneActivation = false;
while (!loadSceneOperation.isDone)
{
if (loadSceneOperation.progress >= 0.9f)
break;
}
loadSceneOperation.allowSceneActivation = true;
yield return loadSceneOperation;
}
private IEnumerator UnloadSceneAsync(string sceneName)
{
yield return null;
if (SceneManager.GetSceneByName(sceneName).IsValid())
SceneManager.UnloadSceneAsync(sceneName);
}
}
}