Fix scene load arguments

This commit is contained in:
2022-08-14 16:49:18 -07:00
parent fd1cfa36d5
commit e1ae7deba5
10 changed files with 30 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ namespace Scampz.GameJam
{
void Start()
{
GameManager.Instance.LoadScene(SceneManager.GetSceneByName(SceneNames.TempleC), LoadSceneMode.Additive);
GameManager.Instance.LoadScene(SceneNames.TempleC, LoadSceneMode.Additive);
}
}
}

View File

@@ -17,21 +17,21 @@ namespace Scampz.GameJam
}
}
public void LoadScene(Scene scene, LoadSceneMode loadSceneMode)
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
{
StartCoroutine(LoadSceneAsync(scene, loadSceneMode));
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
}
public void UnloadScene(Scene scene)
public void UnloadScene(string sceneName)
{
StartCoroutine(UnloadSceneAsync(scene));
StartCoroutine(UnloadSceneAsync(sceneName));
}
private IEnumerator LoadSceneAsync(Scene scene, LoadSceneMode loadSceneMode)
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
{
yield return null;
var loadSceneOperation = SceneManager.LoadSceneAsync(scene.name, loadSceneMode);
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
loadSceneOperation.allowSceneActivation = false;
while (!loadSceneOperation.isDone)
{
@@ -43,11 +43,11 @@ namespace Scampz.GameJam
yield return loadSceneOperation;
}
private IEnumerator UnloadSceneAsync(Scene scene)
private IEnumerator UnloadSceneAsync(string sceneName)
{
yield return null;
if (SceneManager.GetSceneByName(scene.name).IsValid())
SceneManager.UnloadSceneAsync(scene);
if (SceneManager.GetSceneByName(sceneName).IsValid())
SceneManager.UnloadSceneAsync(sceneName);
}
}
}

View File

@@ -9,7 +9,7 @@ namespace Scampz.GameJam
private bool loaded = false;
public Transform spawnPoint;
[SerializeField]
public int scene;
private string scene;
void OnTriggerEnter(Collider collider)
{
@@ -19,7 +19,7 @@ namespace Scampz.GameJam
var player = GameObject.FindWithTag("Player");
var cc = player.GetComponent<CharacterController>();
cc.enabled = false;
GameManager.Instance.LoadScene(SceneManager.GetSceneByName(SceneNames.TempleA), LoadSceneMode.Additive);
GameManager.Instance.LoadScene(scene, LoadSceneMode.Additive);
player.transform.position = spawnPoint.position;
player.transform.rotation = spawnPoint.rotation;
cc.enabled = true;

View File

@@ -10,7 +10,7 @@ namespace Scampz.GameJam
{
if (Input.GetButtonDown(InputOptions.Submit))
{
GameManager.Instance.LoadScene(SceneManager.GetSceneByName(SceneNames.BaseScene), LoadSceneMode.Single);
GameManager.Instance.LoadScene(SceneNames.BaseScene, LoadSceneMode.Single);
}
}
}

View File

@@ -1,12 +1,11 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Scampz.GameJam
{
public class UnloadScene : MonoBehaviour
{
[SerializeField]
public Scene scene;
private string scene;
private bool unloaded = false;
void OnTriggerEnter(Collider collider)