[vc_row full_width =”“ parallax =”“ parallax_image =”“ bg_type =”“ parallax_style =”“ bg_image_new =”“ layer_image =”“ bg_image_repeat =”“ bg_image_size =”“ bg_cstm_size =”“ bg_img_attach =”“ parallax_style =”“ bg_image_posiiton =”“ animation_direction =”“ animation_repeat =”“ video_url =”“ video_url_2 =”“ u_video_url =”“ video_opts =”“ video_poster =”“ u_start_time =”“ u_stop_time =”“ viewport_vdo =”“ enable_controls =”“ bg_override = ”” disable_on_mobile_img_parallax =”” parallax_content =”” parallax_content_sense =”” fadeout_row =”” fadeout_start_effect =”” enable_overlay =”” overlay_color =”” overlay_pattern =”” overlay_pattern_opacity =”“ overlay_pattern_size =”” lay_pattern_attach“ multi_color_overlay_opacity =”” seperator_enable =”” seperator_type =”” seperator_position =”” seperator_shape_size =”” seperator_svg_height = ” seperator_shape_background =”” seperator_shape_border =”” seperator_shape_border_color =”” seperator_shape_border_width =”” icon_type =”” icon =”” icon_size =”” icon_color =”” icon_style =”” icon_color_bg =“” icon_border_style =”” icon_order_b =”“ icon_border_radius =”“ icon_border_spacing =”“ icon_img =”“ img_width =”“ ult_hide_row =”“ ult_hide_row_large_screen =”“ ult_hide_row_desktop =”“ ult_hide_row_tablet =”“ ult_hide_row_row_table_” mobile_hide_row_row_table_“宽度=“ 1/1”] [vc_column_text css =”。vc_custom_1479968746573 {margin-bottom:20px!important;}”]
介绍
导航系统允许可以导航游戏世界的角色。 它使您的角色有能力记住自己想走楼梯到达二楼,或跳起来从沟中恢复。 Unity NavMesh包括以下内容:
- NavMesh是一种路径查找网格,可让您确定游戏世界中的可步行区域。 它通常用于查找游戏世界中从一个可步行位置到另一个位置的路径。
- NavMeshAgent部件可帮助您制作角色,使他们在朝目标前进的过程中彼此保持战略距离。游戏在全球范围内使用NavMesh,并且他们知道如何避免彼此。
- 离网这是一个数字,代表角色可以跳到的高度。 例如,跳过水沟或走过门前的门,
- NavMesh障碍物NavMesh是代理在导航到游戏世界时应避免的对象。
[/ vc_column_text] [vc_column_text css =”。vc_custom_1479968769889 {margin-bottom:20px!important;}”
建立一个NavMesh
从范围创建NavMesh的方式称为NavMesh烘焙。 游戏世界中所有静态的对象都应选择为“导航静态”。 检查导航后,静态单击烘烤按钮。
步骤1:需要将所有地面3d对象选择为“静态”

[/ vc_column_text] [vc_column_text css =”。vc_custom_1479968794049 {margin-bottom:20px!important;}”
第2步:转到窗口>导航

[/ vc_column_text] [vc_column_text css =”。vc_custom_1479968809168 {margin-bottom:20px!important;}”
第3步:选择“对象”>“全部”,然后在“导航静态”上单击,然后单击“烘焙”按钮

烘焙完成后,蓝色表面区域将决定游戏世界中的可行走表面。[/ vc_column_text] [vc_column_text css =”。vc_custom_1479968828449 {margin-bottom:20px!important;}“]
步骤4:现在是时候设置将在Blue Surface上运行的navMeshAgent了。
1.创建一个圆柱体:GameObject> 3D Object> Cylinder。

2.设置下面给出的变换

3.在层次结构中选择“圆柱体”,然后在检查器中选择“添加零件”,然后键入nav mesh agent,它将在圆柱体中添加零件。

4.将脚本添加到Cylinder AgentDirectionScript

5.创建一个空的游戏对象,命名为目标并进行如下所示的转换:

6.将代码添加到AgentDirectionScript
使用UnityEngine;
使用System.Collections;
公共类AgentDirectionScript:MonoBehaviour
{
//引用目标转换
公共转换目标;
无效Start()
{
// navMeshAgent的GetComponent
NavMeshAgent代理= GetComponent ();
//设置navmeshAgent的目标
agent.destination = destination.position;
}
}
7.将目标游戏对象拖放到目标中的AgentDirectionScript中

现在点击播放按钮,Nav Mesh Agent将自动检测步行区域。 }“] [vc_column width =” 1/1“] [vc_row_inner] [vc_column_inner el_class =”“ width =” 1/1“] [vc_raw_html]
=
[/ vc_raw_html] [/ vc_column_inner] [/ vc_row_inner] [/ vc_column] [/ vc_row]