(不太明白原理啥的,先完成期末作业再说~~参考教程:点我)
1、点击Window-AI-Navigation。
2、选中需要烘焙的场景,点击Bake。
3、若场景大的话右下角有进度条显示。
4、烘焙完成
5、给敌人添加Nav Mesh Agent组件,并编写适当脚本实现敌人自动寻路,攻击玩家功能。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class WolfMove : MonoBehaviour
{
// Start is called before the first frame update
private NavMeshAgent nav;
public Transform playerTra;
void Start()
{
nav = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
nav.SetDestination(playerTra.position);
}
}