在此处输入代码
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;
}
}我想连接两个wayPoint系统。当玩家(智能体)到达第一个wayPoint系统的最后一个点时,它遵循第二个路点,这是可能的吗?在代码中,我在到达第一个路点系统的最后一个点后禁用了导航网格代理,并在几秒钟后启用了它,但玩家返回到第一个waypoint系统的第一个点,它不能跳到第二个点
发布于 2018-08-27 21:22:56
我不熟悉航点系统,但是当您到达最后一个点时,您就不能将您的points变量更改为新的航点系统的waypoints吗(它可以在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代理将从第二个航点系统的第一个元素开始。希望这能有所帮助。
https://stackoverflow.com/questions/52037303
复制相似问题