Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var target : Transform;
- var navComponent : NavMeshAgent;
- var MaxDist : float = 5;
- function Start () {
- target = GameObject.FindWithTag("Player").transform;
- navComponent = this.transform.GetComponent(NavMeshAgent);
- }
- function Update () {
- if (target) {
- var dist = Vector3.Distance(target.position, transform.position);
- if (dist < MaxDist){
- if(target) {
- navComponent.SetDestination(target.position);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment