Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created November 29, 2016 14:29
Show Gist options
  • Select an option

  • Save tsubaki/50947ca64fc4879c9bbe16353002ef5d to your computer and use it in GitHub Desktop.

Select an option

Save tsubaki/50947ca64fc4879c9bbe16353002ef5d to your computer and use it in GitHub Desktop.
NavMesh.CalculatePathの最低限の検証用コード
using UnityEngine;
using UnityEngine.AI;
public class FindPath : MonoBehaviour {
[SerializeField] Transform start, goal;
const int maxPosition = 9; // パスの最大登録数
// パスと、座標リスト。使い回す
NavMeshPath path = null;
Vector3[] positions = new Vector3[maxPosition];
void Awake()
{
path = new NavMeshPath();
}
void Start ()
{
// パスの計算
NavMesh.CalculatePath(start.localPosition, goal.localPosition, NavMesh.AllAreas, path);
path.GetCornersNonAlloc(positions);
}
private void OnDrawGizmosSelected()
{
for (int i = 0; i < positions.Length - 1; i++)
{
Gizmos.DrawLine(positions[i], positions[i + 1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment