当前位置:   article > 正文

Unity射线检测_raycashit unity

raycashit unity

射线检测

一般情况是从摄像机到鼠标点击位置生成射线。

  1. void Update () {
  2. if (Input.GetMouseButtonDown(0)) {
  3. Ray ray = _cam.ScreenPointToRay(Input.mousePosition);
  4. if (Physics.Raycast(ray, out hit)) {
  5. }
  6. }
  7. }

返回值hit

hit是RaycasHit类型

  1. public struct RaycastHit
  2. {
  3. public Vector3 point { get; set; }//世界坐标点
  4. public Vector3 normal { get; set; }//法线
  5. public Vector3 barycentricCoordinate { get; set; }//重心坐标
  6. public float distance { get; set; }//距离
  7. public int triangleIndex { get; }//三角形的重心坐标
  8. public Vector2 textureCoord { get; }//UV纹理坐标
  9. public Vector2 textureCoord2 { get; }//次UI纹理坐标
  10. public Vector2 lightmapCoord { get; }//UV光照贴图坐标
  11. public Collider collider { get; }//碰撞器
  12. public Rigidbody rigidbody { get; }//刚体
  13. public Transform transform { get; }//transform属性
  14. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/101005
推荐阅读
相关标签
  

闽ICP备14008679号