前提:随着Unity5.6的推出,我们终于迎来了NavMesh的动态烘培,我们期待已久的功能终于来了,不用再研究A*算法了,话说改进的网格寻路更加方便高效。
Unity5.6 更新概要(中文版):http://mt.sohu.com/it/d20170401/131548770_280780.shtml
Unity5.6更新概要(英文版):https://blogs.unity3d.com/cn/2017/03/31/5-6-is-now-available-and-completes-the-unity-5-cycle/?_ga=1.14498615.1252386216.1491371601
下面就直接进入正题:
首先场景中的物体都要挂上这个脚本NavMeshSourceTag.cs
using UnityEngine;
using UnityEngine.AI;
using System.Collections.Generic;
// Tagging component for use with the LocalNavMeshBuilder
// Supports mesh-filter and terrain - can be extended to physics and/or primitives
[DefaultExecutionOrder(-200)]
public class NavMeshSourceTag : MonoBehaviour
{
// Global containers for all active mesh/terrain tags
public static List<MeshFilter> m_Meshes = new List<MeshFilter>();
public static List<Terrain> m_Terrains = new List<Terrain>();
void OnEnable()
{
var m = GetComponent<MeshFilter>();
if (m != n