From ac82a4146f832909046038e17cd72d64c9ceaa17 Mon Sep 17 00:00:00 2001 From: Alifia Rahmah <13520122@std.stei.itb.ac.id> Date: Sun, 16 Apr 2023 02:45:43 +0700 Subject: [PATCH] fix(pet): integrate pet to gameManager --- Assets/Scripts/GameManager.cs | 4 ++-- Assets/Scripts/Pet/PetFactory.cs | 11 +++++++---- Assets/Scripts/Pet/PetHealth.cs | 6 ++++++ Assets/Scripts/Shop/ShopManager.cs | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 8363cb63..b1a15b7e 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -99,9 +99,9 @@ public class GameManager : MonoBehaviour } } - public void NewPet(string name) + public void NewPet(PetData petData) { - petFactory.FactoryMethod(name); + petFactory.FactoryMethod(petData); } public void NewWeapon(int id) diff --git a/Assets/Scripts/Pet/PetFactory.cs b/Assets/Scripts/Pet/PetFactory.cs index cb125b35..ddab77ae 100644 --- a/Assets/Scripts/Pet/PetFactory.cs +++ b/Assets/Scripts/Pet/PetFactory.cs @@ -16,17 +16,17 @@ public class PetFactory : MonoBehaviour GameObject pet; - public void FactoryMethod(string name) + public void FactoryMethod(PetData petData) { - if (name == "rabbit") + if (petData.name == "rabbit") { pet = Instantiate(petRabbitPrefab, PlayerTransform); } - else if (name == "sparrow") + else if (petData.name == "sparrow") { pet = Instantiate(petSparrowPrefab, PlayerTransform); } - else if (name == "cultist") + else if (petData.name == "cultist") { pet = Instantiate(petCultistPrefab, PlayerTransform); } @@ -46,5 +46,8 @@ public class PetFactory : MonoBehaviour petHealth.pawImage = pawImage; petHealth.petHealthSliderObj = petHealthSlider; } + + // Integrate new pet with GameManager + GameManager.gameManager.currentPet = petData; } } diff --git a/Assets/Scripts/Pet/PetHealth.cs b/Assets/Scripts/Pet/PetHealth.cs index 7dee5bc5..f1e32ded 100644 --- a/Assets/Scripts/Pet/PetHealth.cs +++ b/Assets/Scripts/Pet/PetHealth.cs @@ -28,6 +28,9 @@ public class PetHealth : MonoBehaviour void Start() { + // Set isPetAlive in GameManager to true + GameManager.gameManager.isPetAlive = true; + anim = GetComponent <Animator> (); petAudio = GetComponent <AudioSource> (); petMovement = GetComponent<PetMovement>(); @@ -87,6 +90,9 @@ public class PetHealth : MonoBehaviour { isDead = true; + // Set isPetAlive in gameManager to false + GameManager.gameManager.isPetAlive = false; + // Hide GameObject UI petHealthSliderObj.SetActive(false); pawImage.SetActive(false); diff --git a/Assets/Scripts/Shop/ShopManager.cs b/Assets/Scripts/Shop/ShopManager.cs index ac61e5cc..f983aad9 100644 --- a/Assets/Scripts/Shop/ShopManager.cs +++ b/Assets/Scripts/Shop/ShopManager.cs @@ -13,7 +13,7 @@ public class ShopManager : MonoBehaviour public GameObject petPanelPrefab; public GameObject weaponPanelPrefab; public GameObject parent; - + public HUDManager hudManager; // Coins @@ -129,14 +129,14 @@ public class ShopManager : MonoBehaviour coins.text = GameManager.gameManager.coins.ToString(); // Update pet - GameManager.gameManager.NewPet(petData.name); + GameManager.gameManager.NewPet(petData); GameManager.gameManager.currentPet = petData; GameManager.gameManager.isPetAlive = true; this.petData.Remove(petData); GenerateShopPanel(); } - + } - + } -- GitLab