Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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# 在unity中,为什么我的角色在使用way points时移动如此奇怪,并且所有东西都结巴?_C#_Unity3d - Fatal编程技术网

C# 在unity中,为什么我的角色在使用way points时移动如此奇怪,并且所有东西都结巴?

C# 在unity中,为什么我的角色在使用way points时移动如此奇怪,并且所有东西都结巴?,c#,unity3d,C#,Unity3d,首先是一段显示角色如何移动的视频。 我想做的是让角色不仅仅是移动,而是从一个或多个给定点移动到另一个点 现在我做了些什么 添加到我的层次:地形、主摄像头、平行光、圆柱体和第三个人控制器 在第三个PersonController中,我单击了菜单:组件>导航>导航网格代理 然后将Patroll.cs脚本拖到第三个PersonController 在巡逻区的第三个控制员检查员中,我添加了两个点:墙壁和圆柱体。我希望角色从墙(建筑)走到圆柱体。同样在巡逻区域,我添加了代理:ThirdPersonCon

首先是一段显示角色如何移动的视频。 我想做的是让角色不仅仅是移动,而是从一个或多个给定点移动到另一个点

现在我做了些什么

添加到我的层次:地形、主摄像头、平行光、圆柱体和第三个人控制器

在第三个PersonController中,我单击了菜单:组件>导航>导航网格代理

然后将Patroll.cs脚本拖到第三个PersonController

在巡逻区的第三个控制员检查员中,我添加了两个点:墙壁和圆柱体。我希望角色从墙(建筑)走到圆柱体。同样在巡逻区域,我添加了代理:ThirdPersonController(导航网格代理)

然后在Jierarchy中,我单击了地形,单击了“使其静止”,然后在“窗口>导航>烘焙”菜单中单击,然后单击了“烘焙”按钮

然后,当运行游戏时,角色开始以奇怪的方式自动移动,一切都结巴。 在将巡逻脚本和导航网格代理添加到ThirdPersonController之前,我可以使用WSAD键平滑地移动角色

现在我想做的目标是一旦运行游戏,如果我使用WSAD键靠近或触摸墙壁(建筑物),那么角色将开始自动行走到圆柱体位置。或者在运行游戏时,角色将开始自动从其起始位置行走到墙壁,然后到圆柱体的3个方向点

这是c语言中的巡逻脚本#

使用UnityEngine;
使用系统集合;
公共类巡逻:单一行为{
公共转换[]点;
私有点=0;
公共代理;
//用于初始化
无效开始(){
agent=GetComponent();
//禁用自动制动允许连续移动
//在点之间(即,代理不会随着时间的推移而减速)
//接近目的地)。
agent.autoBraking=false;
GotoNextPoint();
}
void GotoNextPoint(){
//如果未设置任何点,则返回
如果(points.Length==0)
返回;
//将代理设置为转到当前选定的目标。
agent.destination=点[destPoint]。位置;
//选择阵列中的下一个点作为目标,
//如有必要,循环至起点。
destPoint=(destPoint+1)%points.Length;
}
无效更新(){
//当代理到达时,选择下一个目标点
//接近当前的一个。
if(代理剩余距离<0.5f)
GotoNextPoint();
}
}

当ThirdPersonController脚本组件中包含
Patroll
脚本组件时,请清除它。

我禁用了ThirdPersonController检查器中的复选框:第三方用户控件(脚本),但它没有更改任何内容。删除
ThirdPersonController
脚本组件。如果存在
CharacterController
组件,请将其卸下。
using UnityEngine;
using System.Collections;

public class Patroll : MonoBehaviour {

    public Transform[] points;
    private int destPoint = 0;
    public NavMeshAgent agent;

    // Use this for initialization
    void Start () {


        agent = GetComponent<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.Length == 0)
            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.Length;
    }


    void Update () {
        // Choose the next destination point when the agent gets
        // close to the current one.
        if (agent.remainingDistance < 0.5f)
            GotoNextPoint();
    }
}