1 实现绕路功能
(1)首先创建几个物体
(2)然后在Window菜单栏点出Navigation
(3)Plane选中下图这2项
(4)Cube选中下图这2项
(5)Capsule添加Nav Mesh Agent组件
再挂个控制它的脚本上去
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class move : MonoBehaviour {
private NavMeshAgent agent;
void Start () {
agent = GetComponent<NavMeshAgent>();
}
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButton(0))
{
if (Physics.Raycast(ray,out hit))
{
if (hit.transform.name == "Plane")
{
Vector3 v3 = hit.point;
agent.SetDestination(v3);
}
}
}
}
}
现在点击地面Capsule会移动你点击的地点,假如中间隔着Cube,则会绕过去