61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System.Collections;
|
|
using Scampz.GameJam.Assets.Scripts;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance;
|
|
private LevelChanger _levelChanger;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
_levelChanger = GetComponentInChildren<LevelChanger>();
|
|
}
|
|
|
|
|
|
public void LoadScene(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
|
|
{
|
|
StartCoroutine(LoadSceneAsync(sceneName, spawnPoint, loadSceneMode));
|
|
}
|
|
|
|
private IEnumerator LoadSceneAsync(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
|
|
{
|
|
yield return null;
|
|
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
|
|
loadSceneOperation.allowSceneActivation = false;
|
|
while (!loadSceneOperation.isDone)
|
|
{
|
|
yield return null;
|
|
if (loadSceneOperation.progress >= 0.9f)
|
|
break;
|
|
}
|
|
|
|
loadSceneOperation.allowSceneActivation = true;
|
|
yield return loadSceneOperation;
|
|
|
|
if (SceneManager.GetActiveScene().name == sceneName)
|
|
{
|
|
var player = GameObject.FindGameObjectWithTag("Player");
|
|
player.transform.position = spawnPoint.transform.position;
|
|
player.transform.rotation = spawnPoint.transform.rotation;
|
|
|
|
var camera = player.GetComponentInChildren<Camera>();
|
|
if (SceneManager.GetActiveScene().name == SceneNames.WorldMap)
|
|
camera.enabled = true;
|
|
else
|
|
camera.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|