IEnumerator Kongxi(AirWave wave) { yield return(new WaitForSeconds(wave.firstTime)); float waveInterval = Random.Range(wave.waveInterval[0], wave.waveInterval[1]); while (true) { int count = Random.Range(wave.crowNum[0], wave.crowNum[1] + 1); bool isToRight = Random.value <= 0.5f; FightGroup targetGroup = isToRight ? (FightGroup)FightManager.GetInstance().enemyGroup : (FightGroup)FightManager.GetInstance().mineGroup; while (targetGroup.fightUnits.Count == 0) { yield return(null); } Vector3 from, to; if (isToRight) { from = left.localPosition; to = right.localPosition; } else { to = left.localPosition; from = right.localPosition; } for (int i = 0; i < count; i++) { GameObject obj = Instantiate(wuya) as GameObject; obj.transform.parent = transform; obj.transform.localScale = Vector3.one; if (isToRight) { obj.transform.localRotation = Quaternion.Euler(0, 180, 0); } obj.SetActive(true); KongxiWuya kongxiWuya = obj.GetComponent <KongxiWuya>(); Vector3 target = GetOneTarget(targetGroup); kongxiWuya.from = from; kongxiWuya.to = to; kongxiWuya.target = target; kongxiWuya.speed = 100f; yield return(new WaitForSeconds(wave.interval)); } yield return(new WaitForSeconds(waveInterval)); } }
public static GameObject CreateLineAoe(string goName, Transform parent, Vector3 goPos, float xSpeed, bool isRight, HitHandler callBack) { GameObject obj = new GameObject(goName); obj.transform.parent = parent; obj.transform.localScale = Vector3.one; obj.transform.localPosition = goPos; LineAoeMove move = obj.AddComponent <LineAoeMove>(); move.xSpeed = xSpeed; move.direct = isRight ? Vector3.right : -Vector3.right; FightGroup targetGroup = isRight ? (FightGroup)FightManager.GetInstance().enemyGroup : FightManager.GetInstance().mineGroup; move.ToHitUnits = new List <FightUnit>(targetGroup.fightUnits); move.OnHit = callBack; return(obj); }
/// <summary> /// 获取攻击目标 /// </summary> public static FightUnit GetFightTarget(FightUnit self, FightGroup targetGroup) { FightUnit target = null; for (int i = 0; i < targetGroup.fightUnits.Count; i++) { if (targetGroup.fightUnits[i] == self) { continue; } if (target == null) { target = targetGroup.fightUnits[i]; continue; } if (Distance(self, targetGroup.fightUnits[i]) < Distance(self, target)) { target = targetGroup.fightUnits[i]; } } return(target); }