/// <summary> /// Delay the animations between attacking. /// </summary> /// <returns></returns> IEnumerator enemyAttack() { for (int i = 0; i < enemyUnits.Count; i++) { try { //Rotate towards a random target UnitComponent _unitComp = enemyUnits[i].unitComp; _unitComp.transform.LookAt(buildingHealth.transform.position); //Run attack animation enemyUnits[i].unitComp.gameObject.GetComponent <Animator>().Play("UnitAttack"); //Play an appropriate sound //AudioManager.Instance.Play3DSound(SoundLists.weaponClashes, true, 1, enemyUnits[i].unitComp.gameObject, true, false, true); AudioManager.Instance.PlaySound("weaponClash" + Random.Range(1, 2), AudioLists.Combat, AudioMixers.Effects, true, true, false, enemyUnits[i].unitComp.gameObject, 0.5f); } catch { } yield return(new WaitForSeconds(Random.Range(0, 0.05f))); buildingHealth.takeDamage(enemyUnits[i].damage); yield return(new WaitForSeconds(Random.Range(0, 0.02f))); } }