当前位置:网站首页>Unity屏幕坐标转世界坐标,鼠标点击获取三维位置
Unity屏幕坐标转世界坐标,鼠标点击获取三维位置
2022-08-10 05:37:00 【诺贝尔男神获得者】
Unity屏幕坐标转世界坐标,鼠标点击获取三维位置
Raycast():检测射线碰撞的第一个物体信息
//鼠标右键
if (Input.GetMouseButtonDown(1)) {
//发射射线
//Ray ray = new Ray();//创建射线
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//射线检测:得到射线跟碰撞体组件碰撞的位置
//Physics.Raycast();
if (Physics.Raycast(ray, out RaycastHit raycastHit )) {
print(raycastHit.point)//打印射线碰撞的三维的世界坐标
}
}
参数内容大致为:射线、长度、out碰撞信息输出、限制可被检测到的layer层。
layer层控制
layer层一共有32个,由一个int类型数字表示,四个字节32位分别表示对应的layer层
例: 使得射线不与Model层发生碰撞
//得到表示Model层的位为0,其他位为1,使得其他层均可检测,Model不可
int layerMask = ~(1 << 10);
Physics.Raycast(ray, out RaycastHit raycastHit, layerMask)
RaycastAll():检测射线碰撞的多个物体信息
RaycastHit[] hitInfo = Physics.Raycast(ray)
边栏推荐
猜你喜欢
LeetCode 100. The same tree (simple)
样条曲线(下)之插值问题(贝塞尔曲线、B样条和一般样条曲线插值)
LeetCode 292. Nim Game (Simple)
LeetCode refers to the offer 21. Adjust the order of the array so that the odd numbers are in front of the even numbers (simple)
pytorch-09. Multi-classification problem
【烘焙】肉松蛋糕卷
【fiddler3】使用fiddler设置弱网模式
Pytorch配置与实战--Tips
pytorch-06. Logistic regression
浅谈游戏中3种常用阴影渲染技术(1):平面阴影
随机推荐
【接口自动化】
计算数字区间中数字出现次数
酸阻滞树脂
优先级队列,大小顶堆PriorityQueue
LeetCode 1351. Counting Negative Numbers in Ordered Matrices (Simple)
二维卷积定理的验证(下,cv2.filter2D())
Flutter的生命周期
LeetCode Interview Question 17.14 Minimum k Number (Moderate)
Explain the principle of MySql index in detail
自定义View的流程总结学习
STC12C5A60S2单片机WIFI信号扫描报警监视系统信号增强信号过低报警
废水中氟离子去除方法
51单片机AD590温度测量ADC0832运放2.73V减法电压变换
从零开始构建Google Protocol Buffer / protobuf 的helloworld工程(超级详细)
51单片机RS485远程双机多机温度采集主从机多节点蜂鸣器报警
样条曲线(下)之插值问题(贝塞尔曲线、B样条和一般样条曲线插值)
Notes for RNN and Decision Tree
超纯水抛光树脂
【fiddler4】使用fiddler设置简单并发
在TypeScript中使用parseInt()