IEnumerator Move() { Reset(true); yield return(new WaitForSeconds(delayBeforeStart)); StartCoroutine(EmitRoutine()); while (true) { //move to next point, return true if reach if (MoveToPoint(indicatorT, subPath[subWaypointID])) { subWaypointID += 1; //sub waypoint reach, get the next subwaypoint if (subWaypointID >= subPath.Count) //if reach subpath destination, get subpath for next waypoint { subWaypointID = 0; waypointID += 1; if (waypointID >= path.GetPathWPCount()) //if reach path destination, reset to starting pos { Reset(); } else //else get next subpath { subPath = path.GetWPSectionPath(waypointID); } } } yield return(null); } }
public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null) { //this.realAttackRange = GetAttackRange() < 2 ? GetAttackRange() : .5f; Init(); path = p; instanceID = ID; waveID = wID; float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset); float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset); pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ); thisT.position += pathDynamicOffset; if (parentUnit == null) { waypointID = 1; subWaypointID = 0; subPath = path.GetWPSectionPath(waypointID); } else { //inherit stats and path from parent unit waypointID = parentUnit.waypointID; subWaypointID = parentUnit.subWaypointID; subPath = parentUnit.subPath; fullHP = parentUnit.fullHP * parentUnit.spawnUnitHPMultiplier; fullShield = parentUnit.fullShield * parentUnit.spawnUnitHPMultiplier; HP = fullHP; shield = fullShield; } distFromDestination = CalculateDistFromDestination(); if (type == _CreepType.Offense) { StartCoroutine(ScanForTargetRoutine()); StartCoroutine(TurretRoutine()); } if (type == _CreepType.Support) { StartCoroutine(SupportRoutine()); } InitNavMesh(p, ID, wID); }
public override void FixedUpdate() { base.FixedUpdate(); float attackRange = GetAttackRange(); float realStopDistance = attackRange * /* attackRange < 2 ? .65f :*/ .90f; if (!stunned && !dead) { if (useNavMesh) { if (dirtySlow) { agent.speed = GetMoveSpeed(); } if (attacker) { agent.destination = attacker.GetTargetT().position; agent.stoppingDistance = realStopDistance; if (attacker.dead) { tgtList.Remove(attacker); attacker = null; isAlarming = false; } } else if (target != null && !target.dead) { agent.destination = target.GetTargetT().position; agent.stoppingDistance = realStopDistance; } else if (behaviour == Behaviour.Default) { agent.destination = path.wpList[path.wpList.Count - 1].position; agent.stoppingDistance = .02f; } } else if (behaviour == Behaviour.Default) { if (target != null) { MoveToTarget(target.GetTargetT().position, realStopDistance); } else if (MoveToPoint(subPath[subWaypointID])) { subWaypointID += 1; if (subWaypointID >= subPath.Count) { subWaypointID = 0; waypointID += 1; if (waypointID >= path.GetPathWPCount()) { ReachDestination(); } else { subPath = path.GetWPSectionPath(waypointID); } } } } } else if (useNavMesh) { agent.SetDestination(thisT.position); } }