お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
ClosetargetPosition | 期待する移動位置 |
hit | ナビメッシュオブジェクトのヒット情報(ヒットした場合) |
bool エージェントとターゲット位置との間に障害物がある場合は true、そうでない場合は false
エージェントを移動させずにナビメッシュ内の目的地に向かってのパスをトレースします
この関数によりエージェントの位置から 指定されたターゲット位置までの経路をレイでたどります。 もしレイ上で何かとヒットした場合 true を返し、 さらに \hit\ 引数にヒットしたオブジェクトの詳細情報が格納されます。 キャラクターがターゲットのオブジェクトの間に 視界を遮るものがあるか確認するために使用できます。 この関数は Physics.Raycast よりも望ましく、 理由はナビメッシュをより少ない処理オーバーヘッドで 実行できるためです。
var target: Transform; private var agent: NavMeshAgent; function Start () { agent = GetComponent.<NavMeshAgent>(); } function Update() { var hit: NavMeshHit; // Note the negative test condition! if (!agent.Raycast(target.position, hit)) { // Target is "visible" from our position. } }
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Transform target; private NavMeshAgent agent; void Start() { agent = GetComponent<NavMeshAgent>(); } void Update() { NavMeshHit hit; if (!agent.Raycast(target.position, out hit)) { } } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): public target as Transform private agent as NavMeshAgent def Start() as void: agent = GetComponent[of NavMeshAgent]() def Update() as void: hit as NavMeshHit if not agent.Raycast(target.position, ): pass