Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Transform final;
- public GameObject[] ftarget;
- NavMeshAgent agent;
- NavMeshPath path;
- public bool findtarget;
- // Use this for initialization
- void Start () {
- agent = GetComponent<NavMeshAgent>();
- path = new NavMeshPath();
- ftarget = GameObject.FindGameObjectsWithTag("CastleRed");
- //ftarget = GameObject.FindGameObjectWithTag("CastleRed").transform;
- }
- // Update is called once per frame
- void Update () {
- if (!final)
- {
- foreach (GameObject ft in ftarget)
- {
- agent.CalculatePath(ft.transform.position, path);
- if(path.status == NavMeshPathStatus.PathComplete)
- {
- final = ft.transform;
- }
- }
- }
- else
- {
- agent.SetDestination(final.transform.position);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement