using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
private Vector3 clickPosion;
public float speed = 5f;
void Start()
{
clickPosion = transform.position;
}
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
try
{
if (hit.collider.tag == "Ground") //获取点击位置的世界坐标
{
Vector3 v = hit.point;
clickPosion = new Vector3(v.x, transform.position.y, v.z);
}
Unity 3d 如何实现点击屏幕,npc自动移动到点击位置
最新推荐文章于 2024-07-19 14:01:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)