言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

NavMeshAgent.FindClosestEdge

Switch to Manual
public function FindClosestEdge(hit: NavMeshHit): bool;

Parameters

hit 取得できた辺の位置のプロパティ

Returns

bool 最も近い辺が見つかった場合はtrue

Description

最も近いナビメッシュの辺の位置を取得します

The returned NavMeshHit object contains the position and details of the nearest point on the nearest edge of the Navmesh. Since an edge typically corresponds to a wall or other large object, this could be used to make a character take cover as close to the wall as possible.

private var agent: NavMeshAgent;

	function Start () {
		agent = GetComponent.<NavMeshAgent>();
	}


	function Update() {
		// Move to the nearest wall when the mouse is clicked.
		if (Input.GetMouseButtonDown(0)) {
			TakeCover();
		}
	}


	function TakeCover() {
		var hit: NavMeshHit;
		
		if (agent.FindClosestEdge(hit)) {
			agent.SetDestination(hit.position);
		}
	}