Esempio n. 1
0
        public ConnectedWaypoint NextWaypoint(ConnectedWaypoint previousWaypoint)
        {
            ConnectedWaypoint nextWaypoint;

            if (_connections.Count == 0)
            {
                //pas de waypoint
                Debug.LogError("Pas assez de points de passage");
                return(null);
            }

            else if (_connections.Count == 1 && _connections.Contains(previousWaypoint))
            {
                // seulement 1 seul point de passage
                return(previousWaypoint);
            }

            else
            {
                // trouve un point de passage au hasard


                int nextIndex = 0;
                do
                {
                    nextIndex    = UnityEngine.Random.Range(0, _connections.Count);
                    nextWaypoint = _connections[nextIndex];
                } while (nextWaypoint == previousWaypoint);
                return(nextWaypoint);
            }
        }
Esempio n. 2
0
        private void SetDestinationNPC()
        {
            if (_waypointsVisited > 0)
            {
                //Debug.Log("ici");
                ConnectedWaypoint nextWaypoint = _currentWaypoint.NextWaypoint(_previousWaypoint);
                //Debug.LogError(nextWaypoint.transform.position);
                _previousWaypoint = _currentWaypoint;
                _currentWaypoint  = nextWaypoint;
            }

            Vector3 targetVector = _currentWaypoint.transform.position;

            _navMeshAgent.SetDestination(targetVector);
            _travelling = true;
        }
Esempio n. 3
0
        // Start is called before the first frame update
        void Start()
        {
            // récupere tous les waypoint de la scene

            GameObject[] allWaypoints = GameObject.FindGameObjectsWithTag("WP");
            _connections = new List <ConnectedWaypoint>();



            // check si il y a un waypint conencte
            for (int i = 0; i < allWaypoints.Length; i++)
            {
                ConnectedWaypoint nexWaypoint = allWaypoints[i].GetComponent <ConnectedWaypoint>();

                // si on trouve un waypoint
                if (nexWaypoint != null && nexWaypoint != this)
                {
                    if (Vector3.Distance(this.transform.position, nexWaypoint.transform.position) <= _connectivityRadius)
                    {
                        _connections.Add(nexWaypoint);
                    }
                }
            }
        }
Esempio n. 4
0
        // Start is called before the first frame update
        void Start()
        {
            _navMeshAgent = this.GetComponent <NavMeshAgent>();
            if (_navMeshAgent == null)
            {
                Debug.Log("Le navMesh Agent n'est pas attaché au" + gameObject.name);
            }
            else
            {
                if (_currentWaypoint == null)
                {
                    GameObject[] allWaypoints = GameObject.FindGameObjectsWithTag("WP");

                    if (allWaypoints.Length > 0)
                    {
                        while (_currentWaypoint == null)
                        {
                            int random = UnityEngine.Random.Range(0, allWaypoints.Length);

                            ConnectedWaypoint startingWaypoint = allWaypoints[random].GetComponent <ConnectedWaypoint>();

                            if (startingWaypoint != null)
                            {
                                _currentWaypoint = startingWaypoint;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Pas de waypoint sur la scene");
                    }
                }
            }

            SetDestinationNPC();
        }