
As you can see in the image above when I click on the white path the object move perfectly towards the clicked position. When I click on the blue ground the object doesn’t move there but it finds the nearest possible location on the white path, which is the behavior that I don’t want.
I want the object to not move if the click is outside of the white path.
White Path: Navigation Static - Walkable
Blue Ground: Nothing.
Code:
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
navAgent.destination = hit.point;
navAgent.Resume();
}
}
}