返回介绍

NavMeshAgent.SamplePathPosition 样本路径位置

发布于 2019-12-18 15:38:05 字数 3145 浏览 1257 评论 0 收藏 0

JavaScript => public function SamplePathPosition(areaMask: int, maxDistance: float, out hit: NavMeshHit): bool;
C# => public bool SamplePathPosition(int areaMask, float maxDistance, out NavMeshHit hit);

Parameters 参数

areaMaskA bitfield mask specifying which NavMesh areas can be passed when tracing the path.
maxDistanceTerminate scanning the path at this distance.
hitHolds the properties of the resulting location.

Returns 返回

bool True if terminated before reaching the position at maxDistance, false otherwise.

Description 描述

Sample a position along the current path.

沿着当前路径的样本位置。

This function looks ahead a specified distance along the current path. Details of the mesh at that position are then returned in a NavMeshHit object. This could be used, for example, to check the type of surface that lies ahead before the character gets there - a character could raise his gun above his head if he is about to wade through water, say.

该函数看向当前路径前方指定距离。然后在NavMeshHit对象中返回该位置的网格的详细信息。这可以被使用,例如,检查角色到达那儿之前的表面类型——如果角色要涉水,那么他可以把枪举高到头顶之上。

JavaScript:

#pragma strict
public var target: Transform;
public var mesh: NavMesh;
private var agent: NavMeshAgent;
private var waterMask: int;
function Start() {
	agent = GetComponent.<NavMeshAgent>();
	waterMask = 1 << NavMesh.GetAreaFromName("Water");
	agent.SetDestination(target.position);
}
function Update() {
	var hit: NavMeshHit;
	// Check all areas one length unit ahead.
	if (!agent.SamplePathPosition(NavMesh.AllAreas, 1.0F, hit))if ((hit.mask & waterMask) != 0) {
		// Water detected along the path...
	}
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Transform target;
    public NavMesh mesh;
    private NavMeshAgent agent;
    private int waterMask;
 
 
    void Start() {
        agent = GetComponent<NavMeshAgent>();
        waterMask = 1 << NavMesh.GetAreaFromName("Water");
        agent.SetDestination(target.position);
    }
 
 
    void Update() {
        NavMeshHit hit;
 
        // Check all areas one length unit ahead.
        if (!agent.SamplePathPosition(NavMesh.AllAreas, 1.0F, out hit))
            if ((hit.mask & waterMask) != 0) {
            	// Water detected along the path...
            }
    }
}

navmeshagent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文