Hi all,
I’m trying to use NavMesh.FindClosestEdge but it seems i’m not doing it right.
I’ll explain you what I want to do : I’ve got a mesh with it’s verts and tris. I’m using a Physics.Raycast to locate a new point in contact with the mesh. The I would like to find the point of the mesh that is the nearest to this new point.
I don’t really understand the role of the 3rd argument in the fonctions, Maybe the solution is here, but when I change it, there’s no difference.
Here is the part of my code that should do this, but doesn’t.
using UnityEngine;
using System.Collections;
public class Mesure3 : MonoBehaviour {
public Camera mainCamera ;
public GameObject boule ;
private GameObject Click ;
private GameObject Click2 ;
public NavMesh mesh ;
private NavMeshHit nearesthit ;
void Update ()
{
if ( Input.GetButtonDown ("Fire1") )
{
if ( Input.mousePosition.x>120 Input.mousePosition.x<1160 Input.mousePosition.y>120 Input.mousePosition.y<600 )
{
CreatePoint ();
}
}
}
void CreatePoint ()
{
Ray ray = mainCamera.ScreenPointToRay ( Input.mousePosition ) ;
RaycastHit hit ;
if (Physics.Raycast (ray, out hit, 20.0f) )
{
//Create a point where the raycast intersetcs the mesh.
Click = Instantiate (boule, hit.point , Quaternion.identity) as GameObject ;
//Search the nearest point
if (NavMesh.FindClosestEdge(hit.point, out nearesthit, 0))
{
//Create another point on the nearest edge.
Click2 = Instantiate (boule, nearesthit.position , Quaternion.identity) as GameObject ;
}
}
}
}
Thanks in advance
