Esempio n. 1
0
        // Use this for initialization
        void Start()
        {
            GameObject[] allWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");

            _connections = new List <ConnectedWaypoint>();

            for (int i = 0; i < allWaypoints.Length; i++)
            {
                ConnectedWaypoint nextWaypoint = allWaypoints[i].GetComponent <ConnectedWaypoint>();
                if (nextWaypoint != null)
                {
                    if (Vector3.Distance(this.transform.position, nextWaypoint.transform.position) <= _connectivityRadius &&
                        nextWaypoint != this)
                    {
                        _connections.Add(nextWaypoint);
                    }
                }
            }
        }
Esempio n. 2
0
 public ConnectedWaypoint NextWaypoint(ConnectedWaypoint previousWaypoint)
 {
     if (_connections.Count == 0)
     {
         Debug.LogError("Insufficient waypoint count.");
         return(null);
     }
     else if (_connections.Count == 1 && _connections.Contains(previousWaypoint))
     {
         return(previousWaypoint);
     }
     else
     {
         ConnectedWaypoint nextWaypoint;
         int nextIndex = 0;
         do
         {
             nextIndex    = UnityEngine.Random.Range(0, _connections.Count);
             nextWaypoint = _connections[nextIndex];
         } while (nextWaypoint == previousWaypoint);
         return(nextWaypoint);
     }
 }