Last active
November 29, 2016 14:59
-
-
Save tsubaki/1f32ebf2e12b9c251c7fac3fbd7a6e87 to your computer and use it in GitHub Desktop.
NavmeshAgentからパスを取得する
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 System.Collections; | |
using UnityEngine; | |
using UnityEngine.AI; | |
[RequireComponent(typeof(NavMeshAgent))] | |
public class Path2 : MonoBehaviour { | |
[SerializeField] NavMeshAgent agent; | |
[SerializeField] Transform target; | |
const int maxPosition = 9; // パスの最大登録数 | |
// 座標リスト。使い回す | |
Vector3[] positions = new Vector3[maxPosition]; | |
IEnumerator Start () | |
{ | |
agent.updatePosition = false; | |
agent.SetDestination(target.position); | |
yield return new WaitWhile(() => agent.pathStatus != NavMeshPathStatus.PathComplete); | |
agent.path.GetCornersNonAlloc(positions); | |
agent.Stop(); | |
} | |
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