[Unity]什么是RaycastHit?
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/230
了解RaycastHit之前先了解Raycast,具体请看→这里。
RaycastHit类用于存储发射射线后产生的碰撞信息。
Properties
| barycentricCoordinate | The barycentric coordinate of the triangle we hit. |
| collider | The Collider that was hit. |
| distance | The distance from the ray's origin to the impact point. |
| lightmapCoord | The uv lightmap coordinate at the impact point. |
| normal | The normal of the surface the ray hit. |
| point | The impact point in world space where the ray hit the collider. |
| rigidbody | The Rigidbody of the collider that was hit. If the collider is not attached to a rigidbody then it is null. |
| textureCoord | The uv texture coordinate at the collision location. |
| textureCoord2 | The secondary uv texture coordinate at the impact point. |
| transform | The Transform of the rigidbody or collider that was hit. |
| triangleIndex | The index of the triangle that was hit. |
属性
| 重心坐标 | 我们撞击到的三角形的重心坐标。 |
| 碰撞体 | 撞到的碰撞体。 |
| 距离 | 距离,从射线的原始点到影响点。 |
| 光照地图坐标 | 碰撞点处的uv光照贴图坐标。 |
| normal | 射线击中的表面的法线。 |
| point | 在世界坐标中, 射线击中碰撞体的位置的影响点。 |
| rigidbody | 击中对象的刚体,如果collider没有刚体,那就会返回null。 |
| textureCoord | 碰撞位置处的uv纹理坐标。 |
| textureCoord2 | 碰撞点处的次uv纹理坐标。 |
| transform | 被击中的刚体或碰撞体的Transform组件。 |
| triangleIndex | 被击中的三角形的索引。 |
这里声明RaycastHit hit变量,
如果通过hit获取到击中物体的transform,那不就可以控制该物体大小、旋转、移动了吗?
同样,可以触发击中物体的脚本。
参考文档:
[1] Unity Documentation-Scripting API : RaycastHit
[2] Unity中射线Ray和RaycastHit的简单介绍
This article was last edited at