Skip to content

Instantly share code, notes, and snippets.

@dzungpng
Created July 22, 2020 16:50
Show Gist options
  • Save dzungpng/856b459773f8382372f76b66cc5d844d to your computer and use it in GitHub Desktop.
Save dzungpng/856b459773f8382372f76b66cc5d844d to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NavigationAI : MonoBehaviour
{
public GameObject theDestination;
private NavMeshAgent theAgent;
public GameObject walkingBoundary;
private Vector3 agentOrignalPosition;
// Start is called before the first frame update
void Start()
{
theAgent = GetComponent<NavMeshAgent>();
agentOrignalPosition = theAgent.transform.position;
}
// Update is called once per frame
void Update()
{
if (walkingBoundary.GetComponent<MeshCollider>().bounds.Contains(theDestination.transform.position))
{
theAgent.SetDestination(theDestination.transform.position);
}
else
{
theAgent.SetDestination((agentOrignalPosition));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment