当前位置:网站首页>Unity screen coordinates to world coordinates, mouse click to get 3D position
Unity screen coordinates to world coordinates, mouse click to get 3D position
2022-08-10 06:14:00 【Nobel Prize Winner】
Unity screen coordinates to world coordinates, mouse click to get 3D position
Raycast(): first object information for detecting ray collisions
//Right mouse buttonif (Input.GetMouseButtonDown(1)) {// emit rays//Ray ray = new Ray();//Create a rayRay ray = Camera.main.ScreenPointToRay(Input.mousePosition);//Ray detection: get the position where the ray collides with the collider component//Physics.Raycast();if (Physics.Raycast(ray, out RaycastHit raycastHit )) {print(raycastHit.point)//Print the three-dimensional world coordinates of the ray collision}}
The content of the parameters is roughly: ray, length, out collision information output, limit the layer layer that can be detected.
layer control
There are 32 layers in total, which are represented by an int type number.Four bytes and 32 bits respectively represent the corresponding layer layer
Example: Make the ray not collide with the Model layer
//The bit representing the Model layer is 0, and the other bits are 1, so that other layers can be detected, and the Model cannot beint layerMask = ~(1 << 10);Physics.Raycast(ray, out RaycastHit raycastHit, layerMask)
RaycastAll(): Multiple object information for detecting ray collisions
RaycastHit[] hitInfo = Physics.Raycast(ray)
边栏推荐
猜你喜欢
随机推荐
Unity屏幕坐标转世界坐标,鼠标点击获取三维位置
【从零设计 LaTex 模板】1. 一些基础知识
8个问题轻松掌握Unity前向渲染
废酸回收再利用
新建STM32F407ZG Keil5项目
51单片机手动自动智能窗户窗帘控制系统手动自动定时
工业废酸回收工艺
动态规划、背包问题 6/23 101-105
分享一个专业TA的《Shader参考大全》
二叉树 6/20 86-90
(Flutter报错)Cannot run with sound null safety, because the following dependencies
ASP.Net利用代码点击相应按钮来关闭当前的页面(亲测有效)
Tkinter 模块学习
51单片机教室人数进出统计检测数码管显示装置红外传感器
【fiddler2】使用fiddler mock response 数据
过大数组导致爆栈的解决方法记录(堆栈)
剑指 Offer(第 2 版)7/4 1-4
Easy to master Unity of eight prior to rendering
Share a professional TA's "Shader Reference"
探究乱码问题的本源:GBK,UTF8,UTF16,UTF8BOM,ASN1之间的关联