各位我想做一个物体会跟着固定点往前走要怎么做,之前用过一个博主代码是这样子的:
代码如下: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);
}
}
}
但是我使用这个方法每次都是直接走到最后一个点