I'm using NavMesh, and NavMeshAgent for my character movement and Pathfinding.
I made a testing NavMesh with 2 area layers:
0 = Walkable
3 = Water.
In have a click to move script, and i need to get the ID of the NavMesh Area where the player clicked. I tried to get the ID of the layer where the player clicked, using NavMeshHit.mask but is always resulting 0, even if I click where the NavMesh area ID is 3.
From Unity documentation:
Mask specifying NavMesh area at point of hit.
Script:
RaycastHit hit;
NavMeshHit nHit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray, out hit)){
bool hasHit = NavMesh.Raycast (this.transform.position, ray.direction, out nHit, NavMesh.AllAreas);
if (hasHit) {
Debug.Log ("Area ID: " + nHit.mask);
targetPosition = hit.point;
}
}