Created
November 29, 2016 14:29
-
-
Save tsubaki/50947ca64fc4879c9bbe16353002ef5d to your computer and use it in GitHub Desktop.
NavMesh.CalculatePathの最低限の検証用コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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