Exemple #1
0
    public AdvancedWaypoint GetNextNode(AdvancedWaypoint previousNode)
    {
        if (neighbors.Count == 0)
        {
            Debug.LogError("Insuficcient waypoints in node " + gameObject.name);
            return(null);
        }
        else if (neighbors.Count == 1 && neighbors.Contains(previousNode))
        {
            return(previousNode);
        }
        else
        {
            AdvancedWaypoint nextNode;
            int nextIndex = 0;

            do
            {
                nextIndex = UnityEngine.Random.Range(0, neighbors.Count);
                nextNode  = neighbors[nextIndex];
            }while(nextNode == previousNode);

            return(nextNode);
        }
    }
Exemple #2
0
    public void Start()
    {
        GameObject[] allNodes = GameObject.FindGameObjectsWithTag("Waypoint");

        neighbors = new List <AdvancedWaypoint>();

        for (int i = 0; i < allNodes.Length; i++)
        {
            AdvancedWaypoint nextNode = allNodes [i].GetComponent <AdvancedWaypoint> ();

            if (nextNode != null)
            {
                if (Vector3.Distance(this.transform.position, nextNode.transform.position) <= neighboringRadius && nextNode != this)
                {
                    neighbors.Add(nextNode);
                }
            }
        }
    }