From fe2a4bc8f9f71c21273e2278dedb60587be779a8 Mon Sep 17 00:00:00 2001 From: rizkyramadhana <13520151@std.stei.itb.ac.id> Date: Sat, 15 Apr 2023 12:56:15 +0700 Subject: [PATCH] integrate shop with quest Signed-off-by: rizkyramadhana <13520151@std.stei.itb.ac.id> --- Assets/Scenes/Level_01.unity | 6 ++--- Assets/Scripts/Pet/Attacker.cs | 2 +- Assets/Scripts/Quest/QuestDetail.cs | 17 ++++++++++-- .../Scripts/Shopkeeper/ShopkeeperDetector.cs | 26 ++++++++++++++++--- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Assets/Scenes/Level_01.unity b/Assets/Scenes/Level_01.unity index 7555078c..dadff502 100644 --- a/Assets/Scenes/Level_01.unity +++ b/Assets/Scenes/Level_01.unity @@ -9705,7 +9705,7 @@ MonoBehaviour: m_EditorClassIdentifier: playerHealth: {fileID: 1968172701} enemy: {fileID: 152446141947964431, guid: 126948bc699e7da61ac66269cd743206, type: 3} - spawnTime: 3 + spawnTime: 10 spawnPoints: - {fileID: 1269603458} --- !u!4 &1605377956 @@ -9737,7 +9737,7 @@ MonoBehaviour: m_EditorClassIdentifier: playerHealth: {fileID: 1968172701} enemy: {fileID: 3972810617495639857, guid: 9a8837d6dea5bbb4498e9b639db329a0, type: 3} - spawnTime: 3 + spawnTime: 10 spawnPoints: - {fileID: 264091982} --- !u!114 &1605377958 @@ -9754,7 +9754,7 @@ MonoBehaviour: m_EditorClassIdentifier: playerHealth: {fileID: 1968172701} enemy: {fileID: 3663767924688358501, guid: 0d52eb49463a1ffc3a65c5e65d42d89f, type: 3} - spawnTime: 3 + spawnTime: 10 spawnPoints: - {fileID: 557110022} --- !u!1 &1679437323 diff --git a/Assets/Scripts/Pet/Attacker.cs b/Assets/Scripts/Pet/Attacker.cs index 98e45c76..c2a11b0f 100644 --- a/Assets/Scripts/Pet/Attacker.cs +++ b/Assets/Scripts/Pet/Attacker.cs @@ -40,7 +40,7 @@ public class Attacker : MonoBehaviour Debug.Log("menjauhi enemy"); nav.SetDestination(4*transform.position-3*closestEnemy.transform.position); anim.SetTrigger("Jump"); - }else if (distanceEnemy < 5 && timer>1.0f) + }else if (distanceEnemy < 3 && timer>1.0f) { eh.TakeDamage(10,new Vector3(0,0,0)); petAudio.clip = attackClip; diff --git a/Assets/Scripts/Quest/QuestDetail.cs b/Assets/Scripts/Quest/QuestDetail.cs index 84693da1..e56382b6 100644 --- a/Assets/Scripts/Quest/QuestDetail.cs +++ b/Assets/Scripts/Quest/QuestDetail.cs @@ -20,6 +20,9 @@ public class QuestDetail : MonoBehaviour, IDataPersistence public static int zombearKilled; public static int zombunnyKilled; public static int hellephantKilled; + public static bool isQuestFinished=false; + float interval=5.0f; + float timer=5.0f; // Start is called before the first frame update void Start() @@ -41,8 +44,12 @@ public class QuestDetail : MonoBehaviour, IDataPersistence // Update is called once per frame void Update() { - QuestingMechanishm(); - + timer += Time.deltaTime; + if(timer >= interval) + { + QuestingMechanishm(); + } + if(onQuest == true && Panel.activeSelf == false) { OpenQuestStatus(); @@ -55,6 +62,8 @@ public class QuestDetail : MonoBehaviour, IDataPersistence public void questDone (){ QuestDescription.message= "\nCongrats! You have completed the quest"; onQuest = false; + timer=0.0f; + isQuestFinished=true; } public void OpenPanel(){ @@ -79,6 +88,7 @@ public class QuestDetail : MonoBehaviour, IDataPersistence SaveButton.SetActive(false); onQuest = true; + isQuestFinished = false; } if(onQuest== false && questLevel == 3) { @@ -92,6 +102,7 @@ public class QuestDetail : MonoBehaviour, IDataPersistence SaveButton.SetActive(false); onQuest = true; + isQuestFinished = false; } if(onQuest== false && questLevel == 6) { @@ -105,6 +116,7 @@ public class QuestDetail : MonoBehaviour, IDataPersistence SaveButton.SetActive(false); onQuest = true; + isQuestFinished = false; } @@ -119,6 +131,7 @@ public class QuestDetail : MonoBehaviour, IDataPersistence SaveButton.SetActive(false); onQuest = true; + isQuestFinished = false; } if(onQuest == true){ diff --git a/Assets/Scripts/Shopkeeper/ShopkeeperDetector.cs b/Assets/Scripts/Shopkeeper/ShopkeeperDetector.cs index 77a3b7b4..d79eb95c 100644 --- a/Assets/Scripts/Shopkeeper/ShopkeeperDetector.cs +++ b/Assets/Scripts/Shopkeeper/ShopkeeperDetector.cs @@ -6,6 +6,8 @@ public class ShopkeeperDetector : MonoBehaviour { public ShopkeeperManager sm; + bool isShopping=false; + bool inside=false; // Start is called before the first frame update void Start() { @@ -15,20 +17,36 @@ public class ShopkeeperDetector : MonoBehaviour // Update is called once per frame void Update() { - if(Input.GetKey("c")) + if(Input.GetKey("c") && isShopping) { Time.timeScale=1; sm.HideShop(); + isShopping = false; } + + if(QuestDetail.isQuestFinished && Input.GetKey("o") && !isShopping && inside) + { + Debug.Log("masuk"); +Â Â Â Â Â Â Â Â Â Â Â Time.timeScale = 0; +Â Â Â Â Â Â Â Â Â Â Â sm.ShowShop(); + isShopping = true; + } } private void OnTriggerEnter(Collider other) Â Â Â { Â Â Â Â Â Â Â if (other.tag == "Player" && !other.isTrigger) Â Â Â Â Â Â Â { -Â Â Â Â Â Â Â Â Â Â Â Debug.Log("masuk"); -Â Â Â Â Â Â Â Â Â Â Â Time.timeScale = 0; -Â Â Â Â Â Â Â Â Â Â Â sm.ShowShop(); + inside=true; +Â Â Â Â Â Â Â } +Â Â Â } + + private void OnTriggerExit(Collider other) +Â Â Â { +Â Â Â Â Â Â Â if (other.tag == "Player" && !other.isTrigger) +Â Â Â Â Â Â Â { + inside=false; Â Â Â Â Â Â Â } Â Â Â } + } -- GitLab