Unity的Navgation自动寻路
作者:
Zi_Fi | 来源:发表于
2021-02-16 23:37 被阅读0次

image.png

image.png

image.png

image.png

image.png
private NavMeshAgent agent;
void Start()
{
//获取角色上的NavMeshAgent组件
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
//鼠标左键
if (Input.GetMouseButtonDown(0))
{
//射线检测
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
if (isCollider)
{
//hit.point射线触碰的Position
//SetDestination设置下一步的位置
agent.SetDestination(hit.point);
}
}
}
本文标题:Unity的Navgation自动寻路
本文链接:https://www.haomeiwen.com/subject/nzwbxltx.html
网友评论