Advertisement
RealiteeeyyyyTV

Untitled

Dec 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.AI;
  4.  
  5. public class AIMove : MonoBehaviour {
  6.  
  7. [SerializeField]
  8. Transform _destination;
  9.  
  10. NavMeshAgent _navMeshAgent;
  11.  
  12. void Start ()
  13. {
  14. enabled = false;
  15.  
  16. _navMeshAgent = this.GetComponent<NavMeshAgent>();
  17.  
  18. if(_navMeshAgent == null)
  19. {
  20. Debug.LogError("The nav mesh agent component is not attached to " + gameObject.name);
  21. }
  22. else
  23. {
  24. SetDestination();
  25. }
  26.  
  27. }
  28.  
  29. private void SetDestination()
  30. {
  31. if(_destination != null)
  32. {
  33. Vector3 targetVector = _destination.transform.position;
  34. _navMeshAgent.SetDestination(targetVector);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement