transfer between scenes
This commit is contained in:
@@ -32,5 +32,6 @@ public enum RadialMenuActions {
|
||||
Work,
|
||||
Talk,
|
||||
Buy ,
|
||||
Open
|
||||
Open,
|
||||
Enter
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public abstract class BaseInteractableObject : MonoBehaviour
|
||||
{ RadialMenuActions.Work, new RadialMenuActionDescription() { Description = "Work", IsEnabled = false } },
|
||||
{ RadialMenuActions.Eat, new RadialMenuActionDescription() { Description = "Eat", IsEnabled = false } },
|
||||
{ RadialMenuActions.Open, new RadialMenuActionDescription() { Description = "Open", IsEnabled = false } },
|
||||
{ RadialMenuActions.Enter, new RadialMenuActionDescription() { Description = "Enter", IsEnabled = false } },
|
||||
{ RadialMenuActions.Cancel, new RadialMenuActionDescription() { Description = "Cancel", IsEnabled = true } },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ public class Door : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private string _scene;
|
||||
[SerializeField]
|
||||
private string _spawnPointInSceneName;
|
||||
[SerializeField]
|
||||
private string _exitName;
|
||||
|
||||
protected override void PrepareMenuActions()
|
||||
@@ -15,7 +17,7 @@ public class Door : BaseInteractableObject
|
||||
Player.Instance.SetPosition(_interactionPoint.position);
|
||||
}
|
||||
|
||||
_menuActions[RadialMenuActions.Open].IsEnabled = true;
|
||||
_menuActions[RadialMenuActions.Enter].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
@@ -25,7 +27,7 @@ public class Door : BaseInteractableObject
|
||||
PlayerPrefs.SetString("lastExitName", _exitName.ToLower());
|
||||
}
|
||||
|
||||
GameManager.Instance.Scene.Change(_scene);
|
||||
GameManager.Instance.Scene.Change(_scene, _spawnPointInSceneName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,11 @@ public class CameraSystem : MonoBehaviour
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ResetToPlayerPosition();
|
||||
}
|
||||
|
||||
public void ResetToPlayerPosition()
|
||||
{
|
||||
transform.position = Player.Instance.transform.position;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public class GameManager : MonoBehaviour
|
||||
public TimeSystem Time => _timeSystem;
|
||||
public UISystem UI => _uiSystem;
|
||||
|
||||
public CameraSystem Camera =>_cameraSystem;
|
||||
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
|
||||
@@ -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