首页 > 编程语言 > 详细

【Unity3D】自动寻路(Nav Mesh Agent组件)

时间:2015-06-06 14:45:16      阅读:331      评论:0      收藏:0      [点我收藏+]

1.首先添加场景模型

2.为场景模型(寻路路径)添加NavMesh渲染,操作:Windows->Navigation->勾选Navigation Static选项->不勾选Generate选项->Navigation Area选为Walk able->Back栏调整Agent Radius参数->Bake按钮完成寻路渲染

3.为要移动物体添加Nav Mesh Agent组件

4.为要移动物体添加脚本

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class bassTest : MonoBehaviour {
    //移动控制
    private NavMeshAgent Car;
    //货物模型,直接拖拉
    public GameObject Goods;
    //目标点(若要程序调用,请设为Static)
    public Vector3 target;
    void Awake () {
        Car = gameObject.GetComponent<NavMeshAgent> ();

        target = transform.position;

    }
    void Update () {           
        Car.SetDestination (target);
    }
}

 

【Unity3D】自动寻路(Nav Mesh Agent组件)

原文:http://www.cnblogs.com/zhengbin/p/4556538.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!