Version: 2022.3
言語: 日本語
public bool SetDestination (Vector3 target);

パラメーター

target 移動先の目的地点

戻り値

bool 目標地点が正常に要求された場合、 True 、それ以外の場合は False 。

説明

移動先の目的地点を新規設定するか更新して、新たに経路探索を開始します

経路は数フレーム後まで利用可能とならない場合があることに注意してください。 経路が算出されている間、pathPending が true になります。 もし有効な経路が利用可能となったときエージェントは動作を再開します。

using UnityEngine;
using UnityEngine.AI;

public class Example : MonoBehaviour { NavMeshAgent myNavMeshAgent; void Start() { myNavMeshAgent = GetComponent<NavMeshAgent>(); }

void Update() { if (Input.GetMouseButtonDown(0)) { SetDestinationToMousePosition(); } }

void SetDestinationToMousePosition() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { myNavMeshAgent.SetDestination(hit.point); } } }