1、玩家身上挂载nevmeshAgent组件
2、playmove脚本挂载
3、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PlayerMove : MonoBehaviour
{
private NavMeshAgent playerAgent;
// Start is called before the first frame update
void Start()
{
playerAgent=GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollide=Physics.Raycast(ray, out hit);
if (isCollide)
{
playerAgent.SetDestination(hit.point);
}
}
}
}