您的位置:首页 > 移动开发 > Unity3D

动态障碍物操作详细解析

2017-08-26 21:13 155 查看
放入一个plan平面并进行烘焙

再设置一个空物体,里面放入三个障碍物
给三个障碍物挂上Nav MeshObstacle组件
建立游戏对象
挂上Nav Mesh Agent组件
publicclassNavigationTest :MonoBehaviour {
 
    privateNavMeshAgent agent;
         // Use this for initialization
         void Start () {
        agent = GetComponent<NavMeshAgent>();
         }
        
         // Update is called once per frame
         void Update () {
        Ray ray =Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        //不多写参数 就让鼠标点到哪走哪
        if (Physics.Raycast(ray,out
hit))
        {
            if (Input.GetMouseButtonDown(0))
            {
                agent.SetDestination(newVector3(hit.point.x,agent.transform.position.y,hit.point.z));
            }
        }
         }
}
注释:设置障碍物
Move Threshold  移动某个距离进行烘焙
Time To Stationar  物体在某个位置停止一定时间后在烘焙
Carve Only Statio  勾选后不会实时烘焙但是会跟随上面两个条件进行烘焙

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# 脚本 unity