transfer between scenes
This commit is contained in:
@@ -2,8 +2,40 @@ using UnityEngine;
|
||||
|
||||
public class SceneManager
|
||||
{
|
||||
public void Change(string sceneName)
|
||||
private string _spawnLocationName= "DefaultStartPoint";
|
||||
|
||||
public SceneManager()
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_sceneLoaded;
|
||||
}
|
||||
|
||||
public void Change(string sceneName,string spawnLocationName)
|
||||
{
|
||||
_spawnLocationName = spawnLocationName;
|
||||
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SceneManager_sceneLoaded(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.LoadSceneMode arg1)
|
||||
{
|
||||
var spawnPoints = GameObject.FindGameObjectsWithTag("Respawn");
|
||||
if (spawnPoints != null)
|
||||
{
|
||||
foreach (var spawn in spawnPoints)
|
||||
{
|
||||
if (spawn.name == _spawnLocationName)
|
||||
{
|
||||
var interactable = spawn.GetComponent<BaseInteractableObject>();
|
||||
Player.Instance.SetPosition(interactable._interactionPoint.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.Instance.SetPosition(Vector3.zero);
|
||||
}
|
||||
GameManager.Instance.Camera.ResetToPlayerPosition();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user