unity固定点寻路问题询问

各位我想做一个物体会跟着固定点往前走要怎么做,之前用过一个博主代码是这样子的:
代码如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AIPath : MonoBehaviour
{
public NavMeshAgent nma;
public Transform[] pathpoints;
int currentpointindex;
// Start is called before the first frame update
void Start()
{
nma.SetDestination(pathpoints[0].position);
}

// Update is called once per frame
void Update()
{
if(nma.remainingDistance<nma.stoppingDistance)
{
currentpointindex = (currentpointindex + 1) % pathpoints.Length;
nma.SetDestination(pathpoints[currentpointindex].position);
}
}
}

但是我使用这个方法每次都是直接走到最后一个点

currentpointindex = (currentpointindex + 1) % pathpoints.Length;
这句代码保证了currentpointindex 是个循环的,从0到pathpoints.Length-1再回到0,一直循环
如果你的物体飞到最后一个点去了,说明你的pathpoints里一共就一个点

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632