Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class IA : MonoBehaviour
  7. {
  8.    
  9.     NavMeshAgent a;
  10.     public GameObject[] waypoints;
  11.     int waypointn = 0;
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         a = GetComponent<NavMeshAgent>();
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.         a.SetDestination(waypoints[waypointn].transform.position);
  22.     }
  23.  
  24.     private void OnTriggerEnter(Collider other)
  25.     {
  26.         if (waypointn + 1 == waypoints.Length) {
  27.             waypointn = 0;
  28.         } else {
  29.             waypointn++;
  30.         }
  31.     }
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement