Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MuhammadFaizanKhan/fd5efd37ae9baf8fd2ab6aea1dda3219 to your computer and use it in GitHub Desktop.
Save MuhammadFaizanKhan/fd5efd37ae9baf8fd2ab6aea1dda3219 to your computer and use it in GitHub Desktop.
Nav Mesh agent will walk on mouse click position.
using UnityEngine;
using UnityEngine.AI;
public class NavController : MonoBehaviour
{
NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
{
agent.destination = hit.point;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment