Skip to content
Snippets Groups Projects
Commit ac82a414 authored by Alifia Rahmah's avatar Alifia Rahmah
Browse files

fix(pet): integrate pet to gameManager

parent 03eb7b47
Branches
Tags
No related merge requests found
......@@ -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)
......
......@@ -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;
}
}
......@@ -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);
......
......@@ -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();
}
}
}
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