Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created August 24, 2017 17:35
Show Gist options
  • Save unity3dcollege/9116ce36efdddcfbc04b96df86c198d2 to your computer and use it in GitHub Desktop.
Save unity3dcollege/9116ce36efdddcfbc04b96df86c198d2 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.AI;
public class NavMeshClickController : MonoBehaviour
{
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
GetComponent<NavMeshAgent>().SetDestination(hitInfo.point);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment