在我的之前文章中,已经详细写出鼠标控制物体方法,在这里我就只列出代码不进行详细解释了,
private NavMeshAgent agent;
void Start () {
agent = GetComponent<NavMeshAgent>();
}
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
if (Input.GetMouseButtonDown(0))
{
agent.SetDestination(new Vector3(hit.point