From 6db69ec5462cf7252dd47b7909560ffce88f2e29 Mon Sep 17 00:00:00 2001 From: Nigel Sahl <93074692+NerbFox@users.noreply.github.com> Date: Thu, 9 May 2024 11:35:45 +0700 Subject: [PATCH] feat: spawning pet (wip) --- .../Assets/Code/Scripts/KerocoBehaviour.cs | 2 - .../Assets/Code/Scripts/Pet/PetController.cs | 45 +++++++++++++++++++ .../Assets/Code/Scripts/Pet/PetHeal.cs | 7 ++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/KerocoBehaviour.cs b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/KerocoBehaviour.cs index 3598758b..bae82657 100644 --- a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/KerocoBehaviour.cs +++ b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/KerocoBehaviour.cs @@ -40,13 +40,11 @@ public class KerocoBehaviour : MonoBehaviour Collider[] hitCollidersArea = Physics.OverlapSphere(transform.position, attackArea, targetLayer); if (hitCollidersArea.Length > 0 && !isMainPlayer) { - Debug.Log("Enemy in attack area"); // Chase the enemy and attack Chase(hitCollidersArea[0].transform); } else { - Debug.Log("No enemies in attack area"); // Chase the player if no enemies are in the area of attack Chase(MainPlayer.transform); } diff --git a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetController.cs b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetController.cs index 0c911e8e..d039a544 100644 --- a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetController.cs +++ b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetController.cs @@ -8,11 +8,17 @@ public class PetController : MonoBehaviour public GameObject petHeal; public GameObject petAttack; public GameObject petIncrease; + private int[] petHealPositions = { 3, 4, 5 }; + private int[] petAttackPositions = { 0, 1, 2, 6 }; // Start is called before the first frame update void Start() { // array boolean to check if the pet is already in the position bool[] isPetInPosition = new bool[positionToOwner.Length]; + petHeal.GetComponent<PetHeal>().StopHeal(); + petHeal.SetActive(false); + petAttack.SetActive(false); + petIncrease.SetActive(false); } // Update is called once per frame @@ -20,4 +26,43 @@ public class PetController : MonoBehaviour { } + + public bool AddPetHeal() + { + // pet heal can only add to elemen 3,4,5 and 0,1,2,6 is for pet attack + for (int i = 0; i < petHealPositions.Length; i++) + { + if (positionToOwner[i].childCount == 0) + { + GameObject petHealInstance = Instantiate(petHeal, positionToOwner[i]); + petHealInstance.transform.localPosition = Vector3.zero; + petHealInstance.transform.localRotation = Quaternion.identity; + return true; + } + } + return false; + } } + + +//f(positionToOwner[3].childCount == 0) +// { +// petHeal.SetActive(true); +// petHeal.transform.position = positionToOwner[3].position; +// petHeal.transform.rotation = positionToOwner[3].rotation; +// petHeal.transform.parent = positionToOwner[3]; +//} +// else if (positionToOwner[4].childCount == 0) +//{ +// petHeal.SetActive(true); +// petHeal.transform.position = positionToOwner[4].position; +// petHeal.transform.rotation = positionToOwner[4].rotation; +// petHeal.transform.parent = positionToOwner[4]; +//} +//else if (positionToOwner[5].childCount == 0) +//{ +// petHeal.SetActive(true); +// petHeal.transform.position = positionToOwner[5].position; +// petHeal.transform.rotation = positionToOwner[5].rotation; +// petHeal.transform.parent = positionToOwner[5]; +//} \ No newline at end of file diff --git a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetHeal.cs b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetHeal.cs index 246f8e7f..dba34b8e 100644 --- a/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetHeal.cs +++ b/IF3210-2024-Unity-AFK/Assets/Code/Scripts/Pet/PetHeal.cs @@ -26,10 +26,15 @@ public class PetHeal: PetFollowerBehaviour Debug.Log("Player health: " + player.GetComponent<CombatBehavior>().health); } + public void StopHeal() + { + CancelInvoke(nameof(Heal)); + } + // stop healing when the pet is dead onDestroy protected override void OnDestroy() { - CancelInvoke(nameof(Heal)); + StopHeal(); base.OnDestroy(); } } -- GitLab