- Home /
Question by
The-Little-Guy · Jun 02, 2015 at 06:42 PM ·
positionnavmeshscreentoworldpoint
Check if navmesh is at mouse position
What is the best way to test if there is navmesh at a click location?
I currently have this:
protected Vector3 mouseWorldPosition;
void Update () {
if(Input.GetMouseButtonDown(0)){
Vector3 mp = Input.mousePosition;
mp.z = 10f;
mouseWorldPosition = Camera.main.ScreenToWorldPoint(mp);
NavMeshHit hit;
if(NavMesh.SamplePosition(mouseWorldPosition, out hit, 1.0f, NavMesh.AllAreas)){
Debug.Log(hit.position);
}
}
}
I think I need to use NavMesh.SamplePosition to check, but my hit never occurs, am I doing this wrong?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613200550im_/https://answers.unity.com/themes/thub/images/avi.jpg)