using UnityEngine;
using System.Collections;
public class Lu : MonoBehaviour
{
public Camera cam;
// We need to actually hit an object
RaycastHit hitt = new RaycastHit();
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
Physics.Raycast(ray, out hitt, 100);
// Debug.DrawLine(cam.transform.position, ray.direction,Color.red);
if (null != hitt.transform)
{
print(hitt.point);//鼠标点击的坐标
}
}
}
本文介绍了一个简单的Unity脚本,该脚本通过鼠标位置发射射线,并检测射线所击中的对象。具体实现包括获取鼠标在屏幕上的位置,将其转换为射线,使用Unity的Physics.Raycast方法进行碰撞检测。
1万+

被折叠的 条评论
为什么被折叠?



