Beispiel #1
0
    public wayPointConnect NextWayPoint(wayPointConnect previousWaypoint)
    {
        if (connections.Count == 0)
        {
            Debug.LogError("Insufficent way point count");
            return(null);
        }

        else if (connections.Count == 1 && connections.Contains(previousWaypoint))
        {
            return(previousWaypoint);
        }
        else
        {
            wayPointConnect nextWayPoint;
            int             nextIndex = 0;

            do
            {
                nextIndex    = UnityEngine.Random.Range(0, connections.Count);
                nextWayPoint = connections[nextIndex];
            } while (nextWayPoint == previousWaypoint);

            return(nextWayPoint);
        }
    }
    public void SetDesination()
    {
        if (patroling)
        {
            if (wayPointsVisited > 0)
            {
                wayPointConnect newWayPoint = currentWayPoint.NextWayPoint(previousWayPoint);
                previousWayPoint = currentWayPoint;
                currentWayPoint  = newWayPoint;
            }

            Vector3 targetVector = currentWayPoint.transform.position;
            navMeshAgent.SetDestination(targetVector);
            isTravelling = true;
        }

        else if (isApproaching)
        {
            transform.LookAt(player.transform);
            navMeshAgent.isStopped = true;
            navMeshAgent.SetDestination(player.transform.position);
            navMeshAgent.isStopped = false;
        }

        else if (isAttacking)
        {
            navMeshAgent.isStopped = true;
        }

        else
        {
            Debug.Log("NOT SURE WHERE I'M GOING");
        }
    }
    // Use this for initialization
    void Start()
    {
        if (!GetComponent <AudioSource>())
        {
            Debug.Log("No Audio Source");
            gameObject.AddComponent <AudioSource>();
        }
        else
        {
            audioSrc = GetComponent <AudioSource>();
        }



        currentHealth = maxHealth;
        navMeshAgent  = this.GetComponent <NavMeshAgent>();

        //finding waypoints

        if (navMeshAgent == null)
        {
            Debug.LogError("The nav mesh isn't attached to" + gameObject.name);
        }
        else
        {
            if (currentWayPoint == null)
            {
                GameObject[] allWayPoints = GameObject.FindGameObjectsWithTag("wayPointTag");

                if (allWayPoints.Length > 0)
                {
                    while (currentWayPoint == null)
                    {
                        int             random           = UnityEngine.Random.Range(0, allWayPoints.Length);
                        wayPointConnect startingWayPoint = allWayPoints[random].GetComponent <wayPointConnect>();
                        if (startingWayPoint != null)
                        {
                            currentWayPoint = startingWayPoint;
                        }
                    }
                }
            }
            else
            {
                Debug.LogError("Failed to find the wayPoints");
            }
        }

        //SetDesination();
    }
Beispiel #4
0
    private void SetDesination()
    {
        if (patroling)
        {
            if (wayPointsVisited > 0)
            {
                wayPointConnect newWayPoint = currentWayPoint.NextWayPoint(previousWayPoint);
                previousWayPoint = currentWayPoint;
                currentWayPoint  = newWayPoint;
            }

            Vector3 targetVector = currentWayPoint.transform.position;
            navMeshAgent.SetDestination(targetVector);
            isTravelling = true;
        }
    }
Beispiel #5
0
    // Use this for initialization
    public void Start()
    {
        GameObject[] allWayPoints = GameObject.FindGameObjectsWithTag("wayPointTag");
        connections = new List <wayPointConnect>();

        for (int i = 0; i < allWayPoints.Length; i++)
        {
            wayPointConnect nextWayPoint = allWayPoints[i].GetComponent <wayPointConnect>();

            if (nextWayPoint != null)
            {
                if (Vector3.Distance(this.transform.position, nextWayPoint.transform.position) <= connectRadius && nextWayPoint != this)
                {
                    connections.Add(nextWayPoint);
                }
            }
        }
    }