Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使航路点系统的路径保持一致?_C#_Unity3d - Fatal编程技术网

C# 如何使航路点系统的路径保持一致?

C# 如何使航路点系统的路径保持一致?,c#,unity3d,C#,Unity3d,我为路径查找创建了一个航路点系统。我的对象正在沿着路径运行,但当它到达最后一点时,该对象会返回到航路点的第一点。在到达最后一点后,该对象不会离开路径。有什么想法吗? 我想开发一个像temple run这样的3D游戏,玩家使用navmesh和waypoint系统绘制曲线 using UnityEngine; using System.Collections; using System.Collections.Generic; public class NavMover : MonoBehavio

我为路径查找创建了一个航路点系统。我的对象正在沿着路径运行,但当它到达最后一点时,该对象会返回到航路点的第一点。在到达最后一点后,该对象不会离开路径。有什么想法吗? 我想开发一个像temple run这样的3D游戏,玩家使用navmesh和waypoint系统绘制曲线

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();
        }   
    }
}

只需在屏幕外多放一个点,这样他们就会离开屏幕,当他们到达屏幕时,你可以销毁或禁用他们。

我必须销毁哪一项?我不知道你想用这个来实现什么,在没有看到任何代码的情况下,我只是说,你可能应该销毁遵循你的航路点的对象。请提供你的请检查代码。。