public void UpdateMesh() { if (tasks == null) { tasks = new HashSet <Task>(); } if (tasks.Count > 0 && FUtils.All(tasks, task => task == null || task.IsCompleted || task.IsFaulted || task.IsCanceled)) { tasks.Clear(); FUtils.Elvis(eventManager, eventManager => eventManager.DiggingChanged(DiggingMode.NotDigging)); navMesh = new NavMesh(); foreach (VoxelSurface surface in GetComponentsInChildren <VoxelSurface>()) { surface.UpdateMesh(); navMesh.Merge(surface.navMesh, surface.meshCoords, pointDensity, surface.transform); } Debug.Log("Finished generating mesh positions count=" + navMesh.positions.Count); if (navMesh.positions.Count > 0) { player = FindObjectOfType <SimpleController>(); monster = FindObjectOfType <MonsterController>(); localPlayerPosition = transform.InverseTransformPoint(player.transform.position); localCreaturePosition = transform.InverseTransformPoint(monster.transform.position); playerCell = navMesh.ClosestCell(localPlayerPosition); monsterCell = navMesh.ClosestCell(localCreaturePosition); path = navMesh.FindPath(localPlayerPosition, localCreaturePosition); } } }