在此处输入代码
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吗? 在代码中,我在到达第一个航点系统的最后一点后禁用了navmesh代理,并在几秒钟后将其启用,但玩家又回到了第一个wayPoint系统的第一个点,它无法跳转到第二个。
答案 0 :(得分:0)
我对航点系统不熟悉,但是您不能在重新获取最后一个点时将其点变量更改为新航点系统的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代理将从第二个航点系统的第一个元素开始。
希望这会有所帮助。