Ejemplo n.º 1
0
        protected void IncreaseWaypoint()
        {
            pathIndex++;

            if (pathIndex >= path.vectorPath.Count)
            {
                path = null;
                OnPathEnd.Invoke();
                return;
            }

            currentWaypoint = path.vectorPath[pathIndex];
            OnWaypointChange.Invoke();
        }
Ejemplo n.º 2
0
    IEnumerator FollowPath()
    {
        bool followingPath = true;
        int  pathIndex     = 0;

        FacePoint2(path.lookPoints[0].position);

        while (followingPath)
        {
            Vector2 pos2D = (Vector2)transform.position;

            while (path.turnBoundaries[pathIndex].HasCrossedLine(pos2D))
            {
                if (pathIndex == path.finishLineIndex)
                {
                    followingPath = false;
                    OnPathEnd.Invoke(this);
                    break;
                }
                else
                {
                    path.lookPoints[pathIndex].OnCompleted();
                    if (OnCrossedNode != null && OnCrossedNode.GetInvocationList().Length != 0)
                    {
                        OnCrossedNode.Invoke(path.lookPoints[pathIndex]);
                    }
                    pathIndex++;
                    List <Node> uncompletedNodes = new List <Node>();

                    for (int i = pathIndex; i < path.lookPoints.Length; i++)
                    {
                        uncompletedNodes.Add(path.lookPoints[i]);
                    }


                    path = calculatePath(uncompletedNodes, 1);

                    pathIndex = 0;
                }
            }
            if (followingPath)
            {
                FacePoint(path.lookPoints[pathIndex].position);
                transform.Translate(Vector3.up * Time.deltaTime * stats.speed, Space.Self);
            }

            yield return(null);
        }
    }