Unity中的NavMeshAgent

来源:互联网 发布:淘宝红包使用规则 编辑:程序博客网 时间:2024/06/05 07:23

 NavMeshAgent.destination  //  寻路的目标点

NavMeshAgent.remainingDistance  //  距离目标点的距离;



//    鼠标点击那里 物体运动到那里的脚本

//  物体要有Nav Mesh Agent 组件


// 地形需要设置成静态的  之后 在navigation  中 BAKE



NavMeshAgent nav;
   
    
    // Use this for initialization
    void Start () {
        nav = this.GetComponent<NavMeshAgent>();
        player = GameObject.Find("Player");
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray,out hit))
            {
                nav.destination =hit.point;
            }

            
        }
    }



0 0
原创粉丝点击