IEnumerator waitThenStrike() { while (true) { Team before = myTeam(); yield return(new WaitUntil(() => Physics2D.OverlapCircle(transform.position, range, LayerMask.GetMask("Units")))); Transform projectile = ProjectilePool.GiveOutUnit(); projectile.transform.position = transform.position; Attackables = Physics2D.OverlapCircleAll(transform.position, 3, LayerMask.GetMask("Units")); Transform unitToAttack = null; foreach (Collider2D c in Attackables) { if (!c.gameObject.GetComponent <BasicUnit>().myTeam().Equals(myTeam())) { unitToAttack = c.transform; break; } } if (before == myTeam() && unitToAttack != null) { projectile.gameObject.SetActive(true); projectile.position = projectile.position + new Vector3(0, 1, 0); Transform unit = unitToAttack.transform; StartCoroutine(ShootTowardsEnemy(projectile, unit.position)); } else { ProjectilePool.AcceptBackUnit(projectile); } yield return(new WaitForSeconds(.8f)); } }
IEnumerator headTowardsBase(Transform targetBaseTransform) { //establish that no unit is close for DisperseThenTargetThenRecyle() to wait faraway = true; Vector3 targetPos = targetBaseTransform.position; movingUnits = new Queue <Transform>(); unitsToRemove = new Queue <Transform>(); //convenience foreach (Transform unit in transform) { if (targetPos.x < 0) { unit.rotation = Quaternion.Euler(0, 180, 0); } else { unit.rotation = Quaternion.Euler(0, 0, 0); } } while (transform.childCount > 0) { foreach (Transform t in transform) { movingUnits.Enqueue(t); } foreach (Transform t in movingUnits) { bringSingleUnitCloserToLocation(t, targetPos); } for (int i = 0; i < unitsToRemove.Count; i++) { troopPool.AcceptBackUnit(unitsToRemove.Dequeue()); } movingUnits.Clear(); yield return(null); } TCP.AcceptBackUnit(transform); }