Skip to content
Snippets Groups Projects
Commit 6bd23a90 authored by melvinkj's avatar melvinkj
Browse files

feat: save level

parent bf6aba14
Branches
Tags
1 merge request!51Save and Load Game Feature
...@@ -10,6 +10,7 @@ public class GameData ...@@ -10,6 +10,7 @@ public class GameData
public int playerHealth; public int playerHealth;
public Vector3 playerPosition; public Vector3 playerPosition;
public int balance; public int balance;
public int level;
public float damagePercent; public float damagePercent;
...@@ -34,7 +35,7 @@ public class GameData ...@@ -34,7 +35,7 @@ public class GameData
this.damagePercent = 1; this.damagePercent = 1;
this.playerPosition = Vector3.zero; this.playerPosition = Vector3.zero;
this.balance = 0; this.balance = 0;
this.level = 0;
this.healingPetHealths = new List<int>(); this.healingPetHealths = new List<int>();
......
...@@ -5,11 +5,11 @@ using UnityEngine.UI; ...@@ -5,11 +5,11 @@ using UnityEngine.UI;
namespace Nightmare namespace Nightmare
{ {
public class LevelManager : MonoBehaviour public class LevelManager : MonoBehaviour, IDataPersistance
{ {
public string[] levels; public string[] levels;
private int currentLevel = 0; private int currentLevel;
private Scene currentScene; private Scene currentScene;
private PlayerMovement playerMove; private PlayerMovement playerMove;
private Vector3 playerRespawn; private Vector3 playerRespawn;
...@@ -27,8 +27,7 @@ namespace Nightmare ...@@ -27,8 +27,7 @@ namespace Nightmare
void Start() void Start()
{ {
cinema = FindObjectOfType<CinematicController>(); cinema = FindObjectOfType<CinematicController>();
SceneManager.LoadSceneAsync(levels[0], LoadSceneMode.Additive); // SceneManager.LoadSceneAsync(levels[this.currentLevel], LoadSceneMode.Additive); playerMove = FindObjectOfType<PlayerMovement>();
playerMove = FindObjectOfType<PlayerMovement>();
playerRespawn = playerMove.transform.position; playerRespawn = playerMove.transform.position;
} }
...@@ -63,7 +62,7 @@ namespace Nightmare ...@@ -63,7 +62,7 @@ namespace Nightmare
Debug.Log("Setting " + TimerTextComp.gameObject.name + " to inactive."); Debug.Log("Setting " + TimerTextComp.gameObject.name + " to inactive.");
QuestTextComp.gameObject.SetActive(false); QuestTextComp.gameObject.SetActive(false);
Debug.Log("Setting " + QuestTextComp.gameObject.name + " to inactive."); Debug.Log("Setting " + QuestTextComp.gameObject.name + " to inactive.");
} }
else else
{ {
TimerTextComp.gameObject.SetActive(true); TimerTextComp.gameObject.SetActive(true);
...@@ -125,5 +124,15 @@ namespace Nightmare ...@@ -125,5 +124,15 @@ namespace Nightmare
{ {
return currentLevel; return currentLevel;
} }
public void LoadData(GameData data)
{
this.currentLevel = data.level;
SceneManager.LoadSceneAsync(levels[this.currentLevel], LoadSceneMode.Additive);
}
public void SaveData(ref GameData data)
{
data.level = this.currentLevel + 1;
}
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment