C# 如何连接两个航路点系统?

C# 如何连接两个航路点系统?,c#,unity3d,C#,Unity3d,在这里输入代码 List<Transform> points = new List <Transform> (); private int destPoint = 0; private UnityEngine.AI.NavMeshAgent agent; public WaypointSystem path; //Assembly-CSharp-firstpass public float remainingDistance = 0.3f; void Start (

在这里输入代码

List<Transform> points = new List <Transform> ();

private int destPoint = 0;
private UnityEngine.AI.NavMeshAgent agent;

public WaypointSystem path;
//Assembly-CSharp-firstpass
public float remainingDistance = 0.3f;

void Start () {

    points = path.waypoints;

    agent = GetComponent<UnityEngine.AI.NavMeshAgent>();

    // Disabling auto-braking allows for continuous movement
    // between points (ie, the agent doesn't slow down as it
    // approaches a destination point).

       // agent.autoBraking = false;


    //GotoNextPoint();
}


void GotoNextPoint() {
    // Returns if no points have been set up
    if (points.Count == 0)
        return;
    if (destPoint == points.Count) return;

    // Set the agent to go to the currently selected destination.
    agent.destination = points[destPoint].position;


    // Choose the next point in the array as the destination,
    // cycling to the start if necessary.
    //destPoint = (destPoint + 1) % points.Count;
    destPoint = (destPoint + 1);


}


void Update()
{
    // Choose the next destination point when the agent gets
    // close to the current one.
    if (agent.remainingDistance < remainingDistance)
    {
        GotoNextPoint();
    }
   if(destpoint==8)
   agent.enabled=false;


}
}
列表点=新列表();
私有点=0;
私人UnityEngine.AI.NavMesh代理;
公共航路点系统路径;
//装配CSharp第一次通过
公共浮子剩余距离=0.3f;
无效开始(){
点=路径。航路点;
agent=GetComponent();
//禁用自动制动允许连续移动
//在点之间(即,代理不会随着时间的推移而减速)
//接近目的地)。
//agent.autoBraking=false;
//GotoNextPoint();
}
void GotoNextPoint(){
//如果未设置任何点,则返回
如果(points.Count==0)
返回;
if(destPoint==points.Count)返回;
//将代理设置为转到当前选定的目标。
agent.destination=点[destPoint]。位置;
//选择阵列中的下一个点作为目标,
//如有必要,循环至起点。
//destPoint=(destPoint+1)%points.Count;
destPoint=(destPoint+1);
}
无效更新()
{
//当代理到达时,选择下一个目标点
//接近当前的一个。
if(agent.remainingDistance
我想连接两个航路点系统。当玩家(代理)到达第一个航路点系统的最后一个点时,它会跟随第二个航路点。是否可能?
在代码中,我在到达第一个航路点系统的最后一个点后禁用navmesh代理,几秒钟后启用它,但玩家返回到第一个航路点系统的第一个点,它无法跳到第二个。

我不熟悉航路点系统,但是,当您到达最后一个点时,您不能将points变量更改为新航路点系统的
航路点
(可以在
GotoNextPoint
中进行检查)。 也许是这样的:

void GotoNextPoint() {
// Returns if no points have been set up
if (points.Count == 0)
    return;
if (destPoint == points.Count)
{
    points = otherPath.waypoints;
    destPoint = 0;
    return;
}
不要忘记将
destPoint
重置为0,这样navmesh代理将从第二个航路点系统的第一个元素开始。
希望这能有所帮助。

你知道什么不起作用吗?你收到错误了吗?或者它产生了不同的结果?等等?很高兴听到它。:)如果我的回复有帮助(或者需要编辑,请让我知道),请接受它作为答案。提前谢谢。只有当第一个航路点的最后一个点和第二个航路点系统的第一个点靠近时,它才起作用。你知道如果它们“不够近”会发生什么吗?“近”在数字中的含义是什么?如果它们不近,玩家将进入第一个航路点系统的第一个点