private IEnumerator AttackCharacterRoutine(float AttackDamage) { Camera.main.gameObject.GetComponent <FollowCamera>().enabled = false; Character2D AttackingCharacter = SelectedCharacter; Character2D HitCharacter = GetNextCharacter(); float AttackingCharacterSpeed = AttackingCharacter.MaxSpeed; AttackingCharacter.MaxSpeed = 4; SetButtonsInteractable(false); MinionControl2D Minion = SelectedCharacter.GetComponent <MinionControl2D>(); bool IsMinion = Minion != null; if (Minion == null) { Minion = SelectedCharacter.gameObject.AddComponent <MinionControl2D>(); } // Distance should depend on move yield return(StartCoroutine(Minion.WalkToTarget(HitCharacter.transform.transform, 0.05f))); // Attack animation if melee if (CombatHitSound) { MySource.pitch = Random.Range(0.85f, 1.15f); MySource.PlayOneShot(CombatHitSound); } yield return(new WaitForSeconds(0.5f)); // walk back to spawner HitCharacter.GetHit(SelectedCharacter, (int)AttackDamage); CreateHealthPopup(HitCharacter.transform.position, AttackDamage); Vector3 HitCharacterPosition = HitCharacter.transform.position; if (HitCharacter.Health <= 0) { Debug.Log(SelectedCharacter.name + " has defeated " + HitCharacter.name); // Death animation here yield return(new WaitForSeconds(0.5f)); Destroy(HitCharacter.gameObject); } yield return(StartCoroutine(Minion.WalkToTarget(Spawners[SelectedCharacterIndex].transform, 0f))); AttackingCharacter.FaceDirection((HitCharacterPosition - AttackingCharacter.transform.position).normalized); if (!IsMinion) { Destroy(Minion); } AttackingCharacter.MaxSpeed = AttackingCharacterSpeed; if (HitCharacter.Health <= 0) { // Victory dance here yield return(new WaitForSeconds(2.5f)); // Game Over ExitCombat(); } else { SelectNextMonster(); AttackingCharacterLabel.text = SelectedCharacter.name; if (AttackingCharacterLabel.text.Contains("(Clone)")) { AttackingCharacterLabel.text = AttackingCharacterLabel.text.Substring(0, AttackingCharacterLabel.text.IndexOf("(Clone)")); } if (SelectedCharacter == PlayerCharacter) { SetButtonsInteractable(true); } else { yield return(new WaitForSeconds(Random.Range(0.5f, 1.5f))); // now damage the player DoAction(Random.Range(0, 4)); } } Camera.main.gameObject.GetComponent <FollowCamera>().enabled = true; }