1.首先在Unity3D创造中一个正方体,一个圆柱体和一个平面。
2.将正方体和平面设为静态(Static前的方格打勾)
3.在Window中打开AI进行导航网格烘培
4.在add component中添加Nav Mesh Agent(导航网格代理)
这里将Stopping Distance的值修改为0.5。如果使用默认值0,则最后圆柱体会与正方体重合在一起。
5.附加AI脚本给圆柱体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AINavgation : MonoBehaviour
{
public GameObject target;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.destination = target.transform.position;
}
void Update()
{
}
}
6.最终效果
本文地址:https://blog.csdn.net/qq_44842188/article/details/107323241
如对本文有疑问, 点击进行留言回复!!
网友评论