calculatepath and move in navmesh code example
Example: unity calculate path
using UnityEngine;
using UnityEngine.AI;public class ShowGoldenPath : MonoBehaviour
{
public Transform target;
private NavMeshPath path;
private float elapsed = 0.0f;
void Start()
{
path = new NavMeshPath();
elapsed = 0.0f;
} void Update()
{
elapsed += Time.deltaTime;
if (elapsed > 1.0f)
{
elapsed -= 1.0f;
NavMesh.CalculatePath(transform.position, target.position, NavMesh.AllAreas, path);
}
for (int i = 0; i < path.corners.Length - 1; i++)
Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red);
}
}