private void Update() { if (GameMgr.Instacne.state != EGameState.Running) { agent.isStopped = true; return; } agent.isStopped = false; runningtime += Time.deltaTime; if (runningtime > lastAutoAttackStartTime + AtkFrequency)//过了一个周期 { lastAutoAttackStartTime = runningtime; DoAutoAttack(); //自动近战攻击 } UpdateAI(); //主要是设定目标 UpdateSkillAI(); //技能释放 //下面都是被动的,主动的技能通过UI if (targetType == ETroopTargetType.None) { } else if (targetType == ETroopTargetType.AttackBuilding || targetType == ETroopTargetType.RePairBuilding) {//只有工程队可以,都是近战 if (targetBuilding != null) { if (!interActionCheck.list_InterBuilding.Contains(targetBuilding)) { //不在interAction区域内,往前移动 agent.isStopped = false; agent.SetDestination(targetBuilding.transform.position); } else { //已经在范围内了 agent.isStopped = true; } } else { } } else if (targetType == ETroopTargetType.MoveIntoBuilding) { if (targetBuilding != null && targetBuilding.ParentFaction == this.ParentFaction) { CityBuilding parentCity = targetBuilding as CityBuilding; if (!interActionCheck.list_InterBuilding.Contains(targetBuilding)) { //不在interAction区域内,往前移动 agent.isStopped = false; agent.SetDestination(targetBuilding.transform.position); } else { //已经在范围内了 agent.isStopped = true; parentCity.EnterTroop(this); return; } } else if (targetBuilding != null && targetBuilding.ParentFaction != this.ParentFaction) { targetType = ETroopTargetType.AttackBuilding; } } else if (targetType == ETroopTargetType.AttackTroop || targetType == ETroopTargetType.FollowTroop) { if (targetTroop != null) { if (!interActionCheck.list_InterBuilding.Contains(targetBuilding)) { //不在interAction区域内,往前移动 agent.isStopped = false; agent.SetDestination(targetBuilding.transform.position); } else { //已经在范围内了,啥也不干,攻击是自动攻击 agent.isStopped = true; } } else { } } else if (targetType == ETroopTargetType.MoveToPoint) { if (Vector3.Distance(targetPoint, transform.position) <= moveToDiff) { agent.isStopped = true; } else { agent.isStopped = false; agent.SetDestination(targetPoint); } } }
public void Init(CityBuilding building) { this.city = building; }