private Ray ray;
private RaycastHit hit;

private void Update()
{
if (Input.GetMouseButtonDown(1))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
}

}

 

void FixedUpdate()

{

if (Physics.Raycast(ray, out hit, 100))
{
if (hit.collider.tag == “Ground”)
{
Vector3 TargetPoint = new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z);
var targetRotation = Quaternion.LookRotation(TargetPoint – transform.position, Vector3.up); //求出与目标之间的角度
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * RotatSpeed);//旋转之角度与目标对齐
transform.Translate(Vector3.forward * RunSpeed * Time.deltaTime);
}
}
}