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# 我怎样才能找到通往NavMeshAgent目标的路线_C#_Unity3d_Navmesh - Fatal编程技术网

C# 我怎样才能找到通往NavMeshAgent目标的路线

C# 我怎样才能找到通往NavMeshAgent目标的路线,c#,unity3d,navmesh,C#,Unity3d,Navmesh,我想在英雄走过路线之前提前知道路线,并通过线条渲染的方式绘制路线,告诉我是否有可能从代理那里以任何方式找到路线,而不让他面前的尸体知道他已经绘制了路线,如果有任何信息,我将不胜感激 在屏幕截图中,英雄使用NavMeshAgent在点之间移动,我可以找到目标的路线或点吗 public class DisplayedPath : MonoBehaviour { public LineRenderer line; //to hold the line Renderer public T

我想在英雄走过路线之前提前知道路线,并通过线条渲染的方式绘制路线,告诉我是否有可能从代理那里以任何方式找到路线,而不让他面前的尸体知道他已经绘制了路线,如果有任何信息,我将不胜感激

在屏幕截图中,英雄使用NavMeshAgent在点之间移动,我可以找到目标的路线或点吗

public class DisplayedPath : MonoBehaviour
{
    public LineRenderer line; //to hold the line Renderer
    public Transform target; //to hold the transform of the target
    public NavMeshAgent agent; //to hold the agent of this gameObject

    private void Start()
    {
        line = GetComponent<LineRenderer>(); //get the line renderer
        agent = GetComponent<NavMeshAgent>(); //get the agent
                                              //   target = transform;
        StartCoroutine(getPath());
    }

    public IEnumerator getPath()
    {
        // line.SetPosition(0, transform.position); //set the line's origin

        agent.SetDestination(target.position); //create the path
        yield return new WaitForEndOfFrame(); //wait for the path to generate

        DrawPath(agent.path);

        agent.Stop();//add this if you don't want to move the agent
    }

    public void DrawPath(NavMeshPath path)
    {
        if (path.corners.Length < 2) //if the path has 1 or no corners, there is no need
            return;

        line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners

        line.SetPosition(0, transform.GetChild(0).position); //set the line's origin


        for (var i = 1; i < path.corners.Length; i++)
        {
            Vector3 up = path.corners[i];
            up.y += 1.5f;
            line.SetPosition(i, up); //go through each corner and set that to the line renderer's position
        }
    }
}

公共类显示路径:MonoBehavior
{
public LineRenderer line;//保存行渲染器
public Transform target;//保存目标的转换
public NavMeshAgent agent;//持有此游戏对象的代理
私有void Start()
{
line=GetComponent();//获取线条渲染器
agent=GetComponent();//获取代理
//目标=转换;
start例程(getPath());
}
公共IEnumerator getPath()
{
//line.SetPosition(0,transform.position);//设置直线的原点
agent.SetDestination(target.position);//创建路径
yield return new WaitForEndOfFrame();//等待路径生成
DrawPath(agent.path);
agent.Stop();//如果不想移动代理,请添加此项
}
公共无效绘图路径(NavMeshPath路径)
{
if(path.corners.Length<2)//如果路径有1个角或没有角,则不需要
返回;
line.SetVertexCount(path.corners.Length);//将位置数组设置为角数量
line.SetPosition(0,transform.GetChild(0.position);//设置行的原点
对于(变量i=1;i

谢谢Teebkne。

试试看。非常感谢您这就是您需要的