Add scene transitions
This commit is contained in:
8
Assets/Scripts/Animation.meta
Normal file
8
Assets/Scripts/Animation.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e54d2e73072e765469e22a8140f22395
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Animation/LevelChanger.cs
Normal file
15
Assets/Scripts/Animation/LevelChanger.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class LevelChanger : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator animator;
|
||||
|
||||
public void FadeAnimation()
|
||||
{
|
||||
//animator.SetTrigger("FadeOut");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b57ff8788cd779d4d8c417c92aa953e2
|
||||
guid: e1dc86bbd94602841978d59aadff3442
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -6,44 +6,31 @@ namespace Scampz.GameJam
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
private static Animator _animator;
|
||||
private static GameManager _instance;
|
||||
public static GameManager Instance;
|
||||
private LevelChanger _levelChanger;
|
||||
|
||||
public static GameManager Instance
|
||||
private void Awake()
|
||||
{
|
||||
get
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
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;
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
_levelChanger = GetComponentInChildren<LevelChanger>();
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
StartCoroutine(LoadSceneAsync(sceneName, spawnPoint, loadSceneMode));
|
||||
}
|
||||
|
||||
public void UnloadScene(string sceneName)
|
||||
{
|
||||
StartCoroutine(UnloadSceneAsync(sceneName));
|
||||
}
|
||||
|
||||
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
|
||||
private IEnumerator LoadSceneAsync(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
Debug.Log("Start Level Load");
|
||||
yield return null;
|
||||
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
|
||||
loadSceneOperation.allowSceneActivation = false;
|
||||
while (!loadSceneOperation.isDone)
|
||||
@@ -55,13 +42,16 @@ namespace Scampz.GameJam
|
||||
|
||||
loadSceneOperation.allowSceneActivation = true;
|
||||
yield return loadSceneOperation;
|
||||
}
|
||||
|
||||
private IEnumerator UnloadSceneAsync(string sceneName)
|
||||
{
|
||||
yield return null;
|
||||
if (SceneManager.GetSceneByName(sceneName).IsValid())
|
||||
SceneManager.UnloadSceneAsync(sceneName);
|
||||
Debug.Log("Stop Level Load");
|
||||
|
||||
if (SceneManager.GetActiveScene().name == sceneName)
|
||||
{
|
||||
Debug.Log("Move Player");
|
||||
var player = GameObject.FindGameObjectWithTag("Player");
|
||||
player.transform.position = spawnPoint.transform.position;
|
||||
player.transform.rotation = spawnPoint.transform.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class LevelChanger : MonoBehaviour
|
||||
{
|
||||
public Animator animator;
|
||||
public int sceneIndex = 0;
|
||||
|
||||
public static LevelChanger Singleton { get; private set; }
|
||||
|
||||
public void OnTriggerEnter(Collider collider)
|
||||
{
|
||||
//animator.SetTrigger("FadeOut");
|
||||
}
|
||||
|
||||
public void EnableControls()
|
||||
{
|
||||
//InputManager.Instance.enabled = true;
|
||||
}
|
||||
|
||||
public void DisableControls()
|
||||
{
|
||||
//InputManager.Instance.enabled = false;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Singleton is not null && Singleton != this)
|
||||
Destroy(this);
|
||||
else
|
||||
Singleton = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,11 @@ namespace Scampz.GameJam
|
||||
if (!loaded && collider.CompareTag("Player"))
|
||||
{
|
||||
loaded = true;
|
||||
var player = GameObject.FindGameObjectWithTag("Player");
|
||||
var cc = player.GetComponent<CharacterController>();
|
||||
cc.enabled = false;
|
||||
GameManager.Instance.LoadScene(scene, _spawnPoint, LoadSceneMode.Single);
|
||||
cc.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user