Version: 5.6
public Vector3 destination ;

説明

ワールド空間単位でエージェントの目的地を設定し取得します

取得:

このエージェントの目的地の設定を返します。

• If a destination is set but the path is not yet processed the position returned will be valid navmesh position that's closest to the previously set position.
• If the agent has no path or requested path - returns the agents position on the navmesh.
• If the agent is not mapped to the navmesh (e.g. scene has no navmesh) - returns a position at infinity.

設定:

要求された目的地に最も近い有効な NavMesh の位置にエージェントを移動させることを要求します。

• The path result may not become available until after a few frames. Use pathPending to query for outstanding results.
• If it's not possible to find a valid nearby navmesh position (e.g. scene has no navmesh) no path is requested. Use SetDestination and check return value if you need to handle this case explicitly.

using UnityEngine;

[RequireComponent(typeof(NavMeshAgent))] public class FollowTarget : MonoBehaviour { public Transform target; Vector3 destination; NavMeshAgent agent;

void Start() { // Cache agent component and destination agent = GetComponent<NavMeshAgent>(); destination = agent.destination; }

void Update() { // Update destination if the target moves one unit if (Vector3.Distance(destination, target.position) > 1.0f) { destination = target.position; agent.destination = destination; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961