赞
踩
Unity实现简单自动寻路,自动导航
```csharp using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class naviControl : MonoBehaviour { private NavMeshAgent agent; // Start is called before the first frame update void Start() { //获取组件 agent = GetComponent<NavMeshAgent>(); } // 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)) { Vector3 point = hit.point; agent.SetDestination(point); } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。