我创建了一个用于查找路径的航点系统。我的对象遵循路径,但是当它到达最后一点时,对象返回到航点的第一个点,它在到达最后一点后不会离开路径。任何想法? 我想开发一种3D游戏,例如神庙奔跑,在其中玩家可以使用导航网格和航点系统绘制曲线。
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NavMover : MonoBehaviour {
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();
}
}
}
答案 0 :(得分:0)
只需在屏幕外再加1点,它们就会脱离屏幕,到达屏幕时您可以销毁或禁用它们。