//对每个成员分别开启协程 public IEnumerator AttackReach(IAttackResultMode m, float attackValue, GameObject bulletObjectPrefab, Vector3 startPosition) { foreach (Creature c in group) { c.StartCoroutine(c.AttackReach(m, attackValue, bulletObjectPrefab, startPosition)); } yield break; }
//开启协程等待攻击到达 public IEnumerator AttackReach(IAttackResultMode m, float attackValue, GameObject bulletObjectPrefab, Vector3 startPosition) { //生成子弹并设定其目标 if (bulletObjectPrefab != null) { GameObject bulletGameObject = Instantiate(bulletObjectPrefab); bulletGameObject.transform.position = startPosition; BulletObject bulletObject = bulletGameObject.GetComponent <BulletObject>(); bulletObject.target = gameObject; if (bulletObject.spaceObjectPrefab != null) { bulletObject.attackResultMode = m; bulletObject.attackValue = attackValue; yield break;//终止协程,因为bulletObject中会完成攻击,防止计算2次伤害 } yield return(new WaitUntil(bulletObject.ReachSignal)); } //处理攻击结果(各种ITarget的AttackReach最终都会来到这里) nowHealth -= m.getHealthReduction(this, attackValue); }
public IEnumerator AttackReach(IAttackResultMode m, float attackValue, GameObject bulletObjectPrefab, Vector3 startPosition) { creaturesCanAttack = new List <Creature>(); gameObject.GetComponent <Collider>().enabled = false; //生成子弹并设定其目的地 if (bulletObjectPrefab != null) { GameObject bulletGameObject = Instantiate(bulletObjectPrefab); bulletGameObject.transform.position = startPosition; BulletObject bulletObject = bulletGameObject.GetComponent <BulletObject>(); bulletObject.target = gameObject; yield return(new WaitUntil(bulletObject.ReachSignal)); } gameObject.GetComponent <Collider>().enabled = true; yield return(0);//必须等到下一帧触发器结果出来 CreatureGroup group = new CreatureGroup(m.filter.FilterList(creaturesCanAttack, PublicData.noMax)); print("666"); StartCoroutine(group.AttackReach(m, attackValue, null, PublicData.noMeaning)); }
public AttackMode(IAttackResultMode m1, IAttackFlyMode m2) { attackResultMode = m1; attackFlyMode = m2; }
//动画结束后进行结算 public void AttackFly(ITarget t, IAttackResultMode m, float attackValue) { PlayAnimation(); GlobalChangeController.GetInstance().StartCoroutine(t.AttackReach(m, attackValue, null, startPosition)); }