public void Update()
    {
        CheckMySector();
        if (travelling && agent.remainingDistance <= 1.0f)
        {
            myWaypoint.GetComponent <ConnectedWaypoint>().beingVisited = false;
            travelling = false;
            waypointsVisited++;
        }


        else
        {
            if (spotlight.color == Color.red)
            {
                spotlight.color = spotLightOriginalColor;
            }
        }
        if (triggerDict != null)
        {
            List <GameObject> keys = new List <GameObject>(triggerDict.Keys);
            foreach (GameObject s in keys)
            {
                if (s.GetComponent <CreateCollectible>().collected == true && triggerDict[s] == false)
                {
                    placeToCheck   = s.GetComponent <CreateCollectible>().Spawnpoint;
                    triggerDict[s] = true;
                    path           = new NavMeshPath();
                    agent.CalculatePath(placeToCheck.transform.position, path);
                    checkPath(path);
                }
            }
        }
    }
Exemple #2
0
    public void Start()
    {
        CheckSector();
        check = false;


        beingVisited   = false;
        weightWaypoint = 0;
        allWaypoints   = GameObject.FindGameObjectsWithTag("Waypoint");

        for (int i = 0; i < allWaypoints.Length; i++) //creating list of connected weighpoints
        {
            nextWaypoint = allWaypoints[i].GetComponent <ConnectedWaypoint>();
            if (nextWaypoint != this && nextWaypoint != null)
            {
                //if((Vector3.Distance(this.transform.position, nextWaypoint.transform.position) <= _connectivityRadius)) //if near any other waypoints
                //{
                //    _connections.Add(nextWaypoint, 0); //add to dictionary with weight of 0.
                //}

                str2 = nextWaypoint.GetComponent <ConnectedWaypoint>()._sector;

                if (str2.Contains(_sector))
                {
                    _connections.Add(nextWaypoint, 0);
                }
            }
        }
        List <ConnectedWaypoint> keys = new List <ConnectedWaypoint>(_connections.Keys);

        foreach (ConnectedWaypoint item in keys)
        {
            _keys.Add(item);
        }
    }
    public void SetDestination()
    {
        if (waypointsVisited > 0)
        {
            if (_previousWaypoint == null)
            {
                _previousWaypoint = _currentWaypoint;
            }
            ConnectedWaypoint nextWaypoint = _currentWaypoint.NextWaypoint(_previousWaypoint); //gets the next waypoint from the ConnectedWaypoint
            _previousWaypoint = _currentWaypoint;
            _currentWaypoint  = nextWaypoint;
        }

        Vector3 targetVector = _currentWaypoint.transform.position;

        myWaypoint = _currentWaypoint;
        myWaypoint.GetComponent <ConnectedWaypoint>().WeightWaypoint(); //update visiting and weight of waypoint
        agent.SetDestination(targetVector);
        travelling = true;
    }