当前位置:网站首页>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)边栏推荐
猜你喜欢
随机推荐
Tkinter 模块学习
每日刷题(day03)——leetcode 899. 有序队列
二叉树 6/15 76-80
51单片机智能蓝牙APP加油站火灾预警安防防控报警监控系统MQ2DHT11
ASP.Net利用代码点击相应按钮来关闭当前的页面(亲测有效)
视差映射:更逼真的纹理细节表现(上):为什么要使用视差映射
以STM32F103C6T6为例通过配置CubeMX实现EXIT外部中断
制作一个启动软盘并用bochs模拟器启动
二次元卡通渲染-着色
如何实现网格建造系统
51单片机ST188手持人体温度脉搏心率测量仪锂电池充电
2021-04-15 jacoco代码覆盖率统计和白盒测试
在TypeScript中使用parseInt()
初学者也能看懂的Ray March体积云
作为测试,常用的adb命令
【fiddler2】使用fiddler mock response 数据
手把手教你改内核源码--sysfs虚拟文件系统1
开源游戏服务器框架NoahGameFrame(NF)客户端环境搭建(三)
8个问题轻松掌握Unity前向渲染
每日刷题(day02)——leetcode 622. 设计循环队列









