lost me mind i did
This commit is contained in:
@@ -6,8 +6,7 @@ namespace Scampz.GameJam
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public Animator animator;
|
||||
|
||||
private static Animator _animator;
|
||||
private static GameManager _instance;
|
||||
|
||||
public static GameManager Instance
|
||||
@@ -17,26 +16,25 @@ namespace Scampz.GameJam
|
||||
if (!_instance)
|
||||
{
|
||||
_instance = new GameObject().AddComponent<GameManager>();
|
||||
_animator = new GameObject().AddComponent<Animator>();
|
||||
_instance.name = _instance.GetType().ToString();
|
||||
DontDestroyOnLoad(_instance.gameObject);
|
||||
DontDestroyOnLoad(_animator.gameObject);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
void OnEnable()
|
||||
{
|
||||
//SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
//SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
|
||||
public void LoadScene(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
|
||||
var player = GameObject.FindGameObjectWithTag("Player");
|
||||
var cc = player.GetComponent<CharacterController>();
|
||||
cc.enabled = false;
|
||||
player.transform.position = spawnPoint.transform.position;
|
||||
player.transform.rotation = spawnPoint.transform.rotation;
|
||||
cc.enabled = true;
|
||||
}
|
||||
|
||||
public void UnloadScene(string sceneName)
|
||||
@@ -46,12 +44,11 @@ namespace Scampz.GameJam
|
||||
|
||||
private IEnumerator LoadSceneAsync(string sceneName, 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;
|
||||
}
|
||||
@@ -66,10 +63,5 @@ namespace Scampz.GameJam
|
||||
if (SceneManager.GetSceneByName(sceneName).IsValid())
|
||||
SceneManager.UnloadSceneAsync(sceneName);
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
//BGMManager.Instance.PlaySong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
Assets/Scripts/GameManager/PlayerSpawnController.cs
Normal file
28
Assets/Scripts/GameManager/PlayerSpawnController.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerSpawnController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _player;
|
||||
[SerializeField]
|
||||
private GameObject _playerPrefab;
|
||||
[SerializeField]
|
||||
private GameObject _spawnLocation;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (GameObject.FindGameObjectWithTag("Player") != null)
|
||||
{
|
||||
_player = GameObject.FindGameObjectWithTag("Player");
|
||||
_player.transform.position = _spawnLocation.transform.position;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_player = Instantiate(_playerPrefab);
|
||||
_player.transform.position = _spawnLocation.transform.position;
|
||||
DontDestroyOnLoad(_player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/GameManager/PlayerSpawnController.cs.meta
Normal file
11
Assets/Scripts/GameManager/PlayerSpawnController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 743cce483f727904a87ef002d24ec8d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user