Unity 2022 Nav Mesh 自动寻路入门
untiy 2022
window-PackageManager-AINavigation 安装 Install
2.创建一个空物体命名Nav,在其自身挂载 NavMeshSurface
然后点击bake 烘焙地形即可
3.创建palyer和怪物
怪物AI代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class MonsterAI : MonoBehaviour
{
public Transform player;
private NavMeshAgent agent;
private void Start()
{
agent = GetComponent<NavMeshAgent>();
}
private void Update()
{
if (agent != null) {
agent.destination=player.position;
}
}
private void OnDrawGizmos()
{
if (player != null) {
Gizmos.DrawLine(transform.position,player.position);
}
}
}
原文地址:https://blog.csdn.net/weixin_43834973/article/details/143754092
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!