diff --git a/Assets/Prefabs/Pet/Fighter.prefab b/Assets/Prefabs/Pet/Fighter.prefab index 91034397c0f47f2669a4e13345fe0a81cfe2168e..c7c7f652085533563df969098d52fce0903c3978 100644 --- a/Assets/Prefabs/Pet/Fighter.prefab +++ b/Assets/Prefabs/Pet/Fighter.prefab @@ -5603,7 +5603,7 @@ NavMeshAgent: m_Enabled: 1 m_AgentTypeID: 0 m_Radius: 0.5 - m_Speed: 3 + m_Speed: 40 m_Acceleration: 8 avoidancePriority: 50 m_AngularSpeed: 120 diff --git a/Assets/Prefabs/Pet/Healer.prefab b/Assets/Prefabs/Pet/Healer.prefab index 7fe3c1f2b42a53ca135461375ac123f0084c86b7..10dc10d1ca0eef054aaf945139ba6b6c5ccddf92 100644 --- a/Assets/Prefabs/Pet/Healer.prefab +++ b/Assets/Prefabs/Pet/Healer.prefab @@ -190,8 +190,8 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4944737054583867951} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 2.878} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.01, y: 0.01, z: 0.01} m_ConstrainProportionsScale: 0 m_Children: @@ -200,7 +200,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 1.3699999} + m_AnchoredPosition: {x: 0.02, y: 1.23} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} --- !u!223 &5879476890335432378 @@ -395,11 +395,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 46f311046d2104da8b56be3d0a49a119, type: 3} propertyPath: m_LocalPosition.y - value: 0.19 + value: 0.504 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 46f311046d2104da8b56be3d0a49a119, type: 3} propertyPath: m_LocalPosition.z - value: -2.76 + value: -2.8 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 46f311046d2104da8b56be3d0a49a119, type: 3} propertyPath: m_LocalRotation.w diff --git a/Assets/Scripts/Enemy/RajaAbility.cs b/Assets/Scripts/Enemy/RajaAbility.cs index 91ec7c1eb61fb527ba57575ae405fa4e1c6a1d3b..c7f9ea40538ac26359d5f903d8f4ceb23dd59bfd 100644 --- a/Assets/Scripts/Enemy/RajaAbility.cs +++ b/Assets/Scripts/Enemy/RajaAbility.cs @@ -10,13 +10,12 @@ public class RajaAbility : MonoBehaviour Animator anim; GameObject player; PlayerHealth playerHealth; - GameObject petObject; - PetHealth petObjectHealth; - NavMeshAgent navmeshPet; + GameObject[] petObjectsHealer; + GameObject[] petObjectsFighter; + GameObject[] petObjects; PlayerMovement playerMovement; WeaponManager weaponManager; bool playerInRange; - bool petInRange; float timer; public int damageOvertime = 10; public float abilityRadius = 7f; @@ -28,8 +27,10 @@ public class RajaAbility : MonoBehaviour player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent<PlayerHealth>(); playerMovement = player.GetComponent<PlayerMovement>(); - petObject = GameObject.FindGameObjectWithTag("PetBuff"); - petObjectHealth = petObject.GetComponent<PetHealth>(); + petObjectsHealer = GameObject.FindGameObjectsWithTag("PetHealer"); + petObjectsFighter = GameObject.FindGameObjectsWithTag("PetFighter"); + petObjects = petObjectsHealer.Concat(petObjectsFighter).ToArray(); + anim = GetComponent<Animator>(); // Get weapon manager @@ -45,34 +46,41 @@ public class RajaAbility : MonoBehaviour { // Check if player is in radius of its unique ability CheckPlayerInRange(); - CheckPetInRange(); timer += Time.deltaTime; - if (timer >= 1 && (playerInRange || petInRange)) + if (timer >= 1 && playerInRange) { Ability(); } + if(timer >= 1) + { + AbilityAttackPet(); + } + if (!playerInRange && !playerMovement.isTwoTimeSpeed) { playerMovement.speed = playerMovement.originSpeed; } - if (!petInRange && petObject != null) + if(petObjects.Length > 0) { - if (petObject.GetComponent<Follow>() != null) + foreach(GameObject petObject in petObjects) { - navmeshPet.speed = petObject.GetComponent<Follow>().initialSpeed; - } - else if (petObject.GetComponent<FighterMove>() != null) - { - navmeshPet.speed = petObject.GetComponent<FighterMove>().initialSpeed; - } + if(petObject != null) + { + if (!CheckPetInRange(petObject) && petObject.GetComponent<Follow>() != null) + { + petObject.GetComponent<NavMeshAgent>().speed = petObject.GetComponent<Follow>().initialSpeed; + } + if (!CheckPetInRange(petObject) && petObject.GetComponent<FighterMove>() != null) + { + petObject.GetComponent<NavMeshAgent>().speed = petObject.GetComponent<FighterMove>().initialSpeed; + petObject.GetComponent<FighterAttack>().currentDamage = petObject.GetComponent<FighterAttack>().initialDamage; + } + } - if (petObject.GetComponent<FighterAttack>() != null) - { - petObject.GetComponent<FighterAttack>().currentDamage = petObject.GetComponent<FighterAttack>().initialDamage; - } + } } if (playerHealth.currentHealth <= 0) @@ -81,34 +89,9 @@ public class RajaAbility : MonoBehaviour } } - void findNearbyPet() - { - GameObject[] goodPets = GameObject.FindGameObjectsWithTag("PetHealer"); - GameObject[] fighter = GameObject.FindGameObjectsWithTag("PetFighter"); - goodPets = goodPets.Concat(fighter).ToArray(); - float shortestDistance; - float temp; - if (goodPets.Length > 0) - { - shortestDistance = Vector3.Distance(transform.position, goodPets[0].GetComponent<Transform>().position); - foreach (GameObject pet in goodPets) - { - temp = Vector3.Distance(transform.position, pet.GetComponent<Transform>().position); - if (temp < shortestDistance) - { - shortestDistance = temp; - petObject = pet; - petObjectHealth = petObject.GetComponent<PetHealth>(); - navmeshPet = petObject.GetComponent<NavMeshAgent>(); - } - } - } - - } - private void CheckPetInRange() + private bool CheckPetInRange(GameObject petObject) { - findNearbyPet(); - if (petObject != null) + if (petObject!= null) { float distance = Mathf.Sqrt(Mathf.Pow(transform.position.x - petObject.transform.position.x, 2) + Mathf.Pow(transform.position.y - petObject.transform.position.y, 2) + @@ -117,13 +100,18 @@ public class RajaAbility : MonoBehaviour if (distance <= abilityRadius) { - petInRange = true; + return true; } else { - petInRange = false; + return false; } } + else + { + return false; + } + } @@ -146,8 +134,6 @@ public class RajaAbility : MonoBehaviour private void Ability() { - // Reset timer - timer = 0f; // If the player has health to lose... if (playerHealth.currentHealth > 0 && playerInRange) @@ -163,15 +149,27 @@ public class RajaAbility : MonoBehaviour weaponManager.baseDamage -= weaponManager.baseDamage * 0.2f; } } - if (petObjectHealth.currentHealth > 0 && petInRange) - { - petObjectHealth.TakeDamage(damageOvertime); - navmeshPet.speed -= navmeshPet.speed * 0.2f; - if (petObject.GetComponent<FighterAttack>() != null) - { - petObject.GetComponent<FighterAttack>().currentDamage -= 0.2 * petObject.GetComponent<FighterAttack>().currentDamage; + } + private void AbilityAttackPet() + { + timer = 0f; + foreach(GameObject petObj in petObjects) + { + if(petObj != null) + { + petObj.GetComponent<PetHealth>().TakeDamage(damageOvertime); + if (CheckPetInRange(petObj) && petObj.GetComponent<Follow>() != null) + { + petObj.GetComponent<NavMeshAgent>().speed -= petObj.GetComponent<NavMeshAgent>().speed * 0.2f; + + } + if (CheckPetInRange(petObj) && petObj.GetComponent<FighterMove>() != null) + { + petObj.GetComponent<NavMeshAgent>().speed -= petObj.GetComponent<NavMeshAgent>().speed * 0.2f; + petObj.GetComponent<FighterAttack>().currentDamage -= 0.2 * petObj.GetComponent<FighterAttack>().currentDamage; + } }