1 先为地图创建navigation
2 为人物添加nav mesh agent 组件
3 为人物添加移动的脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class hero_mov : MonoBehaviour
{
public NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray,out hit))
{
print(hit.point);
agent.SetDestination(hit.point);
}
}
}
}