From 2f85bd65a2088593d1033ccec97f54451e82b95b Mon Sep 17 00:00:00 2001 From: fernaldyl <90769501+fernaldy112@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:18:46 +0700 Subject: [PATCH] feat: on load method --- Assets/Scenes/Level_01.unity | 12 ++++++++++++ Assets/Scripts/Player/PlayerGold.cs | 5 +++++ Assets/Scripts/Quest/QuestManager.cs | 6 ++++++ Assets/Scripts/Save/SaveHandler.cs | 10 ++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/Level_01.unity b/Assets/Scenes/Level_01.unity index a8620bf..9f7160b 100644 --- a/Assets/Scenes/Level_01.unity +++ b/Assets/Scenes/Level_01.unity @@ -11157,6 +11157,18 @@ PrefabInstance: propertyPath: m_Text value: Save objectReference: {fileID: 0} + - target: {fileID: 11495182, guid: 1ea864171e6acaf46af1353b799103d7, type: 3} + propertyPath: m_Color.b + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11495182, guid: 1ea864171e6acaf46af1353b799103d7, type: 3} + propertyPath: m_Color.g + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11495182, guid: 1ea864171e6acaf46af1353b799103d7, type: 3} + propertyPath: m_Color.r + value: 0 + objectReference: {fileID: 0} - target: {fileID: 22475538, guid: 1ea864171e6acaf46af1353b799103d7, type: 3} propertyPath: m_Pivot.x value: 0.5 diff --git a/Assets/Scripts/Player/PlayerGold.cs b/Assets/Scripts/Player/PlayerGold.cs index 4928dcf..a2234fd 100644 --- a/Assets/Scripts/Player/PlayerGold.cs +++ b/Assets/Scripts/Player/PlayerGold.cs @@ -12,6 +12,11 @@ public class PlayerGold : MonoBehaviour return goldAmount; } + public void setGoldAmount(int goldAmount) + { + this.goldAmount = goldAmount; + } + public void increaseGoldAmount(int gold) { this.goldAmount += gold; diff --git a/Assets/Scripts/Quest/QuestManager.cs b/Assets/Scripts/Quest/QuestManager.cs index 3471bce..fce94f9 100644 --- a/Assets/Scripts/Quest/QuestManager.cs +++ b/Assets/Scripts/Quest/QuestManager.cs @@ -150,4 +150,10 @@ public class QuestManager : MonoBehaviour return activeQuestIdx; } + public void setQuestIdx(int questNum) + { + this.activeQuestIdx = questNum; + nextQuest(); + } + } diff --git a/Assets/Scripts/Save/SaveHandler.cs b/Assets/Scripts/Save/SaveHandler.cs index 23a2696..db9682e 100644 --- a/Assets/Scripts/Save/SaveHandler.cs +++ b/Assets/Scripts/Save/SaveHandler.cs @@ -85,8 +85,14 @@ public class SaveHandler : MonoBehaviour public void OnLoadGame() { - SaveData data = (SaveData)SaveManager.Load("save1"); - Debug.Log(data.questIdx); + GameObject player = GameObject.FindGameObjectWithTag("Player"); + QuestManager questManager = GetComponent<QuestManager>(); + SaveData data = (SaveData)SaveManager.Load("1_left"); // change + player.transform.position = data.playerPosition; + player.transform.rotation = data.playerRotation; + player.GetComponent<PlayerHealth>().currentHealth = data.playerHealth; + player.GetComponent<PlayerGold>().setGoldAmount(data.goldAmount); + questManager.setQuestIdx(data.questIdx); } public Dictionary<int, Tuple<string, DateTime>> preprocessFileName(string[] files_str) -- GitLab