using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Controll : MonoBehaviour
{
// 朝向目标点移动
public GameObject MoveTarget;
public GameObject Player;
Vector3 Movedir;
public float speed;
NavMeshAgent navMeshAgent;
void Start()
{
navMeshAgent = Player.GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray OneClickPointRay = Camera.main.ScreenPointToRay(Input.mousePosition);//从摄像机出发向鼠标点击的位置
RaycastHit OutPoint;
if (Physics.Raycast(OneClickPointRay, out OutPoint))//如果投射射线撞击到一个物体成功
{
navMeshAgent.SetDestination(OutPoint.point);
}
}
}
}