IEnumerator EmitRoutine() { yield return(new WaitForSeconds(delayBeforeStart)); List <PathSection> PSList = path.GetPath(); while (currentPS == null) { Reset(PSList); yield return(null); } while (true) { //~ indicatorT.Translate(Vector3.forward*stepDist); //~ indicator.Emit(3); if (currentPathID != currentPS.GetPathID()) { GetSubPath(); while (subPath.Count == 0) { GetSubPath(); } indicatorT.position = subPath[subWPCounter]; } float dist = Vector3.Distance(subPath[subWPCounter], indicatorT.position); float thisStep = stepDist; if (dist < stepDist) { thisStep = stepDist - dist; indicatorT.position = subPath[subWPCounter]; subWPCounter += 1; if (subWPCounter >= subPath.Count) { wpCounter += 1; if (!GetNextWP()) { thisStep = 0; } } } if (thisStep > 0) { //rotate towards destination Vector3 pos = new Vector3(subPath[subWPCounter].x, indicatorT.position.y, subPath[subWPCounter].z); if ((pos - indicatorT.position).magnitude > 0) { Quaternion wantedRot = Quaternion.LookRotation(pos - indicatorT.position); //set particlesystem to wantedRot indicator.startRotation = (wantedRot.eulerAngles.y - 45) * Mathf.Deg2Rad; } indicatorT.LookAt(subPath[subWPCounter]); //move, with speed take distance into accrount so the unit wont over shoot indicatorT.Translate(Vector3.forward * thisStep); indicator.Emit(1); } yield return(new WaitForSeconds(updateRate * Time.timeScale)); } }
//get subpath from current pathSection private void GetSubPath() { subPath = currentPS.GetSectionPath(); currentPathID = currentPS.GetPathID(); subWPCounter = 0; }