Advertisement
RealiteeeyyyyTV

Untitled

Dec 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 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. _navMeshAgent = this.GetComponent<NavMeshAgent>();
  15.  
  16. if(_navMeshAgent == null)
  17. {
  18. Debug.LogError("The nav mesh agent component is not attached to " + gameObject.name);
  19. }
  20. else
  21. {
  22. SetDestination();
  23. }
  24.  
  25. }
  26.  
  27. private void SetDestination()
  28. {
  29. if(_destination != null)
  30. {
  31. Vector3 targetVector = _destination.transform.position;
  32. _navMeshAgent.SetDestination(targetVector);
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement