返回介绍

NavMeshPath.corners 拐角

发布于 2019-12-18 15:38:06 字数 2228 浏览 1376 评论 0 收藏 0

JavaScript => public var corners: Vector3[];
C# => public Vector3[] corners;

Description 描述

Corner points of the path. (Read Only)

路径拐角点。(只读)

Also known as “waypoints”, the corners define the places along a path where it changes direction (ie, the path consists of a number of straight-line moves between corners).

也称作“waypoints”,拐角沿着路径改变的方向定义位置(即,路径包括若干个角落之间的直线移动)。

JavaScript:

// Calculate the length of a NavMeshPath. A character will
// typically move a slightly longer distance than this as a
// result of its steering behaviour.
function PathLength(path: NavMeshPath) {
	// The length is implicitly zero if there aren't at least
	// two corners in the path.
	if (path.corners.Length < 2)
		return 0;
 
	var previousCorner = path.corners[0];
	var lengthSoFar = 0.0;
 
	// Calculate the total distance by adding up the lengths
	// of the straight lines between corners.
	for (var i = 1; i < path.corners.Length; i++) {
		var currentCorner = path.corners[i];
		lengthSoFar += Vector3.Distance(previousCorner, currentCorner);
		previousCorner = currentCorner;
	}
 
	return lengthSoFar;
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    float PathLength(NavMeshPath path) {
        if (path.corners.Length < 2)
            return 0;
 
        Vector3 previousCorner = path.corners[0];
        float lengthSoFar = 0.0F;
        int i = 1;
        while (i < path.corners.Length) {
            Vector3 currentCorner = path.corners[i];
            lengthSoFar += Vector3.Distance(previousCorner, currentCorner);
            previousCorner = currentCorner;
            i++;
        }
        return lengthSoFar;
    }
}

navmeshpath

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

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

发布评论

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