Esempio n. 1
0
    protected void generateNewPath()
    {
        if (current != null)
        {
            // We know where are
            List <int> nodes = waypoints.navGraph.nodes();

            if (nodes.Count > 0)
            {
                // Pick a random node to aim for
                int target = nodes[rnd.Next(nodes.Count)];
                Debug.Log("New target: " + target);
                // Find a path from here to there
                path = pathfinder.findPath(current.Value, target);
                Debug.Log("New path: " + writePath(path));
            }
            else
            {
                // There are zero nodes
                Debug.Log("No waypoints - can't select new target");
            }
        }
        else
        {
            // We don't know where we are

            // Find the nearest waypoint
            int?target = waypoints.findNearest(transform.position);

            if (target != null)
            {
                // Go to target
                path.Clear();
                path.Add(target.Value);

                Debug.Log("Heading for nearest waypoint: " + target);
            }
            else
            {
                // Couldn't find a waypoint
                Debug.Log("Can't find nearby waypoint to target");
            }
        }
    }