Edit: Unity version 5.6.0f3
The scripting manual here: Unity - Scripting API: NavMeshData
States that it is a public variable (as is rotation) but they are unavailable.
public Mesh CreateMesh()
{
Mesh mesh = new Mesh();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uvs;
mesh.RecalculateNormals();
for (int i = 0; i < mesh.vertices.Length; i++)
{
// For each set of triangles which are Vector3's, we will add them to the NavMesh
TerrainType[] regions = GameObject.FindGameObjectWithTag("GameManager").GetComponent<MapGenerator>().regions;
if( vertices[i].y < regions[3].height || vertices[i].y >= regions[13].height)
{
// Not Walkable
} else
{
// Walkable
NavMeshData tmp = new NavMeshData();
tmp.position = vertices[i]; // <--- This is the part that doesn't work.
NavMesh.AddNavMeshData(tmp, vertices[i], Quaternion.AngleAxis(90, Vector3.up));
}
}
return mesh;
}
This is the code I am going through. I create a mesh from PerlinNoise, and I want to take the vertices, and if it’s in a certain ‘height’ range, then I want to add them as walkable terrain for the NavMesh. Then I will update the navmesh when it loads, and then I can have a random map with navmesh generated on the fly… however… I have hit a wall.