Beispiel #1
0
    IEnumerator EmitRoutine()
    {
        yield return(null);

        Transform[] waypoints = path.GetPath();


        while (true)
        {
            float dist = Vector3.Distance(waypoints[wpCounter].position, indicatorT.position);

            float thisStep = stepDist;
            if (dist < stepDist)
            {
                thisStep            = stepDist - dist;
                indicatorT.position = waypoints[wpCounter].position;

                wpCounter += 1;
                if (wpCounter >= waypoints.Length)
                {
                    wpCounter           = 0;
                    indicatorT.position = waypoints[wpCounter].position;
                }
            }

            if (thisStep > 0)
            {
                //rotate towards destination
                Vector3 pos = new Vector3(waypoints[wpCounter].position.x, waypoints[wpCounter].position.y, waypoints[wpCounter].position.z);
                Vector3 dir = pos - indicatorT.position;
                //~ Quaternion wantedRot;
                if (dir != Vector3.zero)
                {
                    Quaternion wantedRot = Quaternion.LookRotation(dir);

                    //set particlesystem to wantedRot
                    indicator.startRotation = (wantedRot.eulerAngles.y - 45) * Mathf.Deg2Rad;

                    indicatorT.LookAt(waypoints[wpCounter]);

                    //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));
        }
    }
    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));
        }
    }