当前位置:网站首页>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)边栏推荐
猜你喜欢
随机推荐
lua循环
从零开始构建Google Protocol Buffer / protobuf 的helloworld工程(超级详细)
在Unity中让主摄像机发射一条射线,判断射线在游戏场景中所碰撞的游戏物体名字和标签名称(亲测有效)
51单片机营养液自动配置搅拌系统TDS浓度采集自动加水加营养液
Explore the origin of the garbled problem: the association between GBK, UTF8, UTF16, UTF8BOM, and ASN1
Linux的文件IO与标准IO,以及IO缓存
每日刷题(day01)——leetcode 53. 最大子数组和
2021-04-15 jacoco代码覆盖率统计和白盒测试
在Unity中利用代码动态更改场景中的天空盒
C#热更新比Lua好在哪里?
最简单的字符设备驱动
以STM32F103C6T6为例通过配置CubeMX实现EXIT外部中断
qemu和主机共享磁盘
动态规划、背包问题 6/24 106-110
剑指 Offer(第 2 版)7/6 9-13
详解 Hough 变换(下)圆形检测
二次元卡通渲染-着色
mysql分组排序并取各分组前几个数据
clickhouse出现数据重复问题
51单片机BH1750智能补光灯台灯光强光照恒流源LED控制系统









