Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.AI;
- public class AIMove : MonoBehaviour {
- [SerializeField]
- Transform _destination;
- NavMeshAgent _navMeshAgent;
- void Start ()
- {
- _navMeshAgent = this.GetComponent<NavMeshAgent>();
- if(_navMeshAgent == null)
- {
- Debug.LogError("The nav mesh agent component is not attached to " + gameObject.name);
- }
- else
- {
- SetDestination();
- }
- }
- private void SetDestination()
- {
- if(_destination != null)
- {
- Vector3 targetVector = _destination.transform.position;
- _navMeshAgent.SetDestination(targetVector);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement